Want to send parameters with a custom send event

I am creating a library. Here is an example

[Event (name="eventAction", type="something")] public function create_new_customer(phone_number:String):void { -------------; ----; ------------; rpc.addEventListener(Event.COMPLETE, onCreate_returns); } private function onCreate_returns(evt:Event):void { var ob:Object = evt.target.getResponse(); dispatchEvent(new something("eventAction")); } 

I have a listener for this event in the application. Therefore, when I manually send the event, I want the "ob" to send as a parameter. How to do it?

+6
actionscript-3
source share
3 answers

You need to create your own event class with additional properties for transferring data with it. In your case, you can use a class like

 public class YourEvent extends Event { public static const SOMETHING_HAPPENED: String = "somethingHappend"; public var data: Object; public function YourEvent(type:String, data: Object, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = data; } override public function clone():Event { return new YourEvent (type, data, bubbles, cancelable); } } 

then when you send yo:

 dispatchEvent(new YourEvent(YourEvent.SOMETHING_HAPPENED, ob)); 
+20
source share

In AS3, you can use a DataEvent:

Example:

dispatchEvent (new DataEvent (type: String [, bubbles: Boolean = false, cancelable: Boolean = false, data: String]);

Instead of the sample data, I showed the parameters of the DataEvent.

Hope this helps.

Best regards, RA.

+5
source share

Make your custom event portable for this ob object. Pass it to custom event ctor and voila!

0
source share

All Articles