EventDelegate
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Classpath: | org.asapframework.events.EventDelegate |
| File last modified: | Friday, 15 September 2006, 11:31:08 |
This class acts as a replacement for Macromedia's mx.utils.Delegate, as that class cannot be used with MTASC.
Based on Till Schneidereit's simple but elegant solution: http://lists.motion-twin.com/archives/mtasc/2005-April/001602.html
This class allows for extra parameters to be passed to the event handler.
The class method create creates a new Function object that passes the scope to the input object, rather than the object calling the function.
Summary
Class methods
Class methods
create
static function create (
scope:Object,
method:Function) : Function
Creates an event delegate relation.
Parameters:
scope :
Object to call method on.
method:
Method to call.
params:
All additional parameters will be passed onto method on execution.
Usage:
Using a reference:
To remove a listener using a delegate:
var myDelegate:Function = EventDelegate.create(this, onXMLloaded); myXML = new XML(); myXML.onLoad = myDelegate;Without reference:
myButton.addEventListener( "onClicked", EventDelegate.create(this, onExitButtonClicked))To remove a listener using a delegate:
// use instance property mLoaderDoneEventDelegate = EventDelegate.create(this, handleImageLoaded); mImageLoader.addEventListener(LoaderEvent.ON_DONE, mLoaderDoneEventDelegate);After having loaded:
mImageLoader.removeEventListener(LoaderEvent.ON_DONE, mLoaderDoneEventDelegate);