Skip to content

Instantly share code, notes, and snippets.

@FrancisVarga
Created April 19, 2012 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancisVarga/2420226 to your computer and use it in GitHub Desktop.
Save FrancisVarga/2420226 to your computer and use it in GitHub Desktop.
Self disposer EventDispatcher
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