Home

Archive » March, 2010 «

AS3 Signals Bubbling note

Sunday, March 07th, 2010 | Author: dehash

Working with this now and just a note that it looks like a way to bubble Signals from a nested display class is as follows:

public var deluxeSignal:DeluxeSignal = new DeluxeSignal(this);

deluxeSignal.dispatch(new GenericEvent(true));

and the listening class further up the display list implements IBubbleEventHandler and requires the following method:

public function onEventBubbled(e:IEvent):void {
trace(e +"-"+ e.target +"-"+ e.currentTarget +"-"+ e.signal);
}

- – -
Added a quick example below with source code using the current signals release unedited
here

PS there is an excellent Signals video tutorial here

- – -
Update: Added a new version of the simple example that works with the latest Signals release (0.7). The onEventBubbled method now has a boolean return value to determine whether to continue bubbling or stop.
The new example code can be downloaded here

- – -

Some ideas on passing parameters:
var deluxeSignal:DeluxeSignal = new DeluxeSignal(this);
deluxeSignal.dispatch(new GenericEvent(true));
Here you are passing “this”, ie the sending instance, as the GenericEvent event target so that it is available as the event.target within onEventBubbled(event:IEvent).

Alternately pass in a Value Object (VO) instead of “this” to pass more precise and data typed parameters (you would need to give it a “parent” property) or another option is to extend GenericEvent and give it some custom properties which can be read within onEventBubbled.

Category: Code Examples, Flash | 14 Comments