package net.gerhut.eventUtils
{
import flash.events.EventDispatcher;
public class OnceEventDispatcher
{
public static function add(eventDispatcher:EventDispatcher, type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
{
var onceListener:OnceListener = new OnceListener(eventDispatcher, type, listener, useCapture);
eventDispatcher.addEventListener(type, onceListener.outputListener, useCapture, priority, useWeakReference);
}
}
}
import flash.events.Event;
import flash.events.EventDispatcher;
class OnceListener
{
private var type:String;
private var eventDispatcher:EventDispatcher;
private var originalListener:Function;
private var useCapture:Boolean;
public function OnceListener(eventDispatcher:EventDispatcher, type:String, originalListener:Function, useCapture:Boolean=false)
{
this.type = type;
this.eventDispatcher = eventDispatcher;
this.originalListener = originalListener;
this.useCapture = useCapture;
}
public function outputListener(event:Event):void
{
eventDispatcher.removeEventListener(type, outputListener, useCapture);
originalListener(event);
}
}