Sending Custom data with Deluxe Signals

83 views
Skip to first unread message

eco_bach

unread,
Nov 28, 2010, 11:26:23 PM11/28/10
to as3-signals
Hi
These are 'beginners' questions but please bear with me.

How do you create a custom signall that both bubbles AND carries
custom data using AS3Sgnals?


I've created a DeluxeSignal called 'selectSignal'.
I also need to make this signal both bubble AND to pass custom data
with it.

So I've created a bubbling Generic Event which I pass as an argument
when dispatching like so-

// CODE START
var event:IEvent = new GenericEvent();
event.bubbles = true;
selectSignal.dispatch(event);
// CODE END

Any help appreciated!

Ben Kanizay

unread,
Nov 29, 2010, 5:03:46 AM11/29/10
to as3-s...@googlegroups.com
There's always more than one way, but you could extend GenericEvent and have your custom properties in that class, and access them in your event handler. Eg

package {
import org.osflash.signals.events.GenericEvent;

public class CustomEvent extends GenericEvent {

private var _simpleValue:String;
public function get simpleValue() : String { return _simpleValue; }
public function set simpleValue(val:String) : void { _simpleValue = val; }

public function CustomEvent(bubbles:Boolean = true) {
super(bubbles);
}

}
}


In your example below your event would be a CustomEvent and you would do the following...

event.simpleValue = "Hello";
selectSignal.dispatch(event);

Then wherever your handler is...

private function selectSignalHandler(event:CustomEvent) : void {
trace(event.simpleValue);
}


Its a very basic example but you get the idea. You could also ditch the setter and add the value(s) via the CustomEvent constructor and have them as read-only via the getter.

Ben

Reply all
Reply to author
Forward
0 new messages