Created
April 19, 2012 10:51
-
-
Save FrancisVarga/2420226 to your computer and use it in GitHub Desktop.
Self disposer EventDispatcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.crowdpark.core | |
{ | |
import flash.events.EventDispatcher; | |
import flash.events.IEventDispatcher; | |
import flash.events.Event; | |
/** | |
* @author francis | |
*/ | |
public class SelfDisposedEventDispatcher implements IEventDispatcher | |
{ | |
private var _eventDispatcher : EventDispatcher; | |
private var _listenerList : Array; | |
public function BaseTableEventDispatcher() | |
{ | |
_eventDispatcher = new EventDispatcher(); | |
_listenerList = new Array(); | |
} | |
public function dispose() : void | |
{ | |
var totalListeners : uint = _listenerList.length; | |
for (var i : int = 0; i < totalListeners; i++) | |
{ | |
var args : Array = _listenerList[i]; | |
if (_eventDispatcher.hasEventListener(args[0])) | |
{ | |
/** | |
* // Index of arguments | |
* type[0] : String, listener[1] : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false | |
*/ | |
_eventDispatcher.removeEventListener(args[0], args[1]); | |
} | |
} | |
_listenerList.splice(0, totalListeners); | |
} | |
public function addEventListener(type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void | |
{ | |
_listenerList.push(arguments); | |
_eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference); | |
} | |
public function removeEventListener(type : String, listener : Function, useCapture : Boolean = false) : void | |
{ | |
_eventDispatcher.removeEventListener(type, listener, useCapture); | |
} | |
public function dispatchEvent(event : Event) : Boolean | |
{ | |
return dispatchEvent(event); | |
} | |
public function hasEventListener(type : String) : Boolean | |
{ | |
return hasEventListener(type); | |
} | |
public function willTrigger(type : String) : Boolean | |
{ | |
return willTrigger(type); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment