Permalink
Browse files

Added ability to delete all eventlistners or all of a certain type...…

… as well as view the event listener list.
  • Loading branch information...
1 parent 3cd020a commit 30ee4b96911d301ea09516324241c4bc9d734f16 @KesslerConsulting committed Jul 16, 2013
Showing with 118 additions and 0 deletions.
  1. +118 −0 frameworks/projects/framework/src/mx/core/FlexSprite.as
@@ -21,6 +21,9 @@ package mx.core
{
import flash.display.Sprite;
+import flash.events.Event;
+import flash.events.EventPhase;
+import mx.collections.ArrayList;
import mx.utils.NameUtil;
/**
@@ -87,12 +90,72 @@ public class FlexSprite extends Sprite
}
}
+
+ //--------------------------------------------------------------------------
+ //
+ // Properties
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ protected var alEventListenerList:ArrayList = new ArrayList();
+
+
+ /**
+ * Gets the arraylist that
+ */
+ public function get eventListenerList():ArrayList
+ {
+ return alEventListenerList;
+ }
+
+
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
+ /**
+ * Override addEventListener to store the entries in an event array list.
+ */
+ override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
+ {
+ alEventListenerList.addItem({typeValue:type, listenerValue:listener, useCaptureValue:useCapture});
+
+ super.addEventListener(type, listener, useCapture, priority, useWeakReference);
+ }
+
+
+ /**
+ * Override the removeEventListener to remove the entries in an event array list.
+ */
+ override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
+ {
+ var oTemp:Object;
+ var nListenerTotal:uint = alEventListenerList.length;
+ var nLoopingIndex:uint = 0;
+
+
+ super.removeEventListener(type, listener, useCapture);
+
+
+ for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
+ {
+ oTemp = alEventListenerList.getItemAt(nLoopingIndex);
+
+ if (oTemp.typeValue == type && oTemp.listenerValue == listener && oTemp.useCaptureValue == useCapture)
+ {
+ alEventListenerList.removeItemAt(nLoopingIndex);
+ return;
+ }
+ }
+
+ }
+
+
/**
* Returns a string indicating the location of this object
* within the hierarchy of DisplayObjects in the Application.
@@ -116,6 +179,61 @@ public class FlexSprite extends Sprite
{
return NameUtil.displayObjectToString(this);
}
+
+
+ //--------------------------------------------------------------------------
+ //
+ // Methods
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * Removes all event listeners.
+ */
+ public function removeAllEventListeners():void
+ {
+ var oTemp:Object;
+ var nListenerTotal:uint = alEventListenerList.length;
+ var nLoopingIndex:uint = 0;
+
+
+ for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
+ {
+ oTemp = alEventListenerList.getItemAt(nLoopingIndex);
+
+ super.removeEventListener(oTemp.typeValue, oTemp.listenerValue, oTemp.useCaptureValue);
+ }
+
+ alEventListenerList.removeAll();
+ }
+
+
+ /**
+ * Removes all event listeners of the specified type.
+ */
+ public function removeEventListenersByType(type:String):void
+ {
+ var oTemp:Object;
+ var nListenerTotal:uint = alEventListenerList.length;
+ var nLoopingIndex:uint = 0;
+
+
+
+ for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
+ {
+ oTemp = alEventListenerList.getItemAt(nLoopingIndex);
+
+ if (oTemp.typeValue == type)
+ {
+ super.removeEventListener(oTemp.typeValue, oTemp.listenerValue, oTemp.useCaptureValue);
+
+ alEventListenerList.removeItemAt(nLoopingIndex);
+ nListenerTotal -= 1;
+ nLoopingIndex -= 1;
+ }
+ }
+
+ }
}
}

0 comments on commit 30ee4b9

Please sign in to comment.