Sep 11, 2008

Event Fast Forward

In some cases you just want to pass along an Event to it's parent. Instead of writing a new relay function like..

myEvtDisptchr.addEventListener(Event.TYPE, _onEvent_handler);
function _onEvent_handler($evt:Event):void{
dispatchEvent($evt.clone());
}

..you can just use the inherited function dispatchEvent:

myEvtDisptchr.addEventListener(Event.TYPE, dispatchEvent);

you can also redirect an Event:

myEvtDisptchr.addEventListener(Event.TYPE, myOtherEvtDisptchr.dispatchEvent);
Simple.

Share this Post


                           

Comments


PeterH     Mar 16, 2010
I use this technique to pass events up to parent controllers. I believe it follows the chain-of-responsibility-pattern.

Diane     Nov 27, 2008
I think your site is very good and complete, but the information you have here,

Roselyn     Nov 04, 2008
A good site, good short contents of the good work. I have loved your site :,

Tink     Sep 12, 2008
When re-dispatching an event manually, you don't need to call the clone method, it is automatically called by the player

i.e. the following do the same thing

dispatchEvent( $evt.clone() );
dispatchEvent( $evt );



Speak






Submit »