topical media & game development
lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction.ax
lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction.ax
(swf
)
[ flash
]
flex
package org.as3lib.kitchensync.action
{
import flash.events.*;
import org.as3lib.kitchensync.core.*;
An action for calling an asynchronous function that is expected to dipatch an event when
it completes.
author: Mims Wright
@since 1.5
public class @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction extends KSFunction
{
a reference to the event dispatcher
protected var _completeEventDispatcher:IEventDispatcher;
the type of event to listen for
protected var _completeEventType:String;
Constructor.
parameter: delay The time to wait before calling the function.
parameter: func The function to call
parameter: completeEventDispatcher The IEventDispatcher that will fire the event signaling that the
function is complete.
parameter: completeEventType The type (name) of the event that will be fired when complete.
parameter: args All additional parameters will be passed as arguments to the function when it is called.
public function @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction(delay:*, func:Function, completeEventDispatcher:IEventDispatcher, completeEventType:String, ...args)
{
super(delay, func);
this._args = args;
_completeEventDispatcher = completeEventDispatcher;
_completeEventType = completeEventType;
_completeEventDispatcher.addEventListener(_completeEventType, onFunctionComplete, false, 0, true);
}
Executes the function when the delay has elapsed.
override public function update(currentTimestamp:Timestamp):void {
if (startTimeHasElapsed) {
invoke();
unregister();
}
}
Event listener that is called when the asyncronous function is completed.
protected function onFunctionComplete(event:Event):void {
_completeEventDispatcher.removeEventListener(_completeEventType, onFunctionComplete);
complete();
}
override public function clone():IAction {
var clone:@ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction = new @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSAsynchronousFunction(_delay, _func, _completeEventDispatcher, _completeEventType);
clone._args = _args;
clone.duration = _duration;
clone.autoDelete = _autoDelete;
return clone;
}
override public function kill():void {
super.kill();
_completeEventDispatcher = null;
}
}
}
(C) Æliens
19/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.