views:

2578

answers:

3

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 to this event in app side. So when I manually dispatch event I want the "ob" to be sent as a parameter. How to do it?

A: 

Make your custom event carry this ob object. Pass it to the custom event's ctor and voila!

dirkgently
thanks ... would be more helpful if i got a simple example as I am new to as!
kartik
+6  A: 

You need to create a custom event class with extra properties to pass data with it. In your case you could 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, date: 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 yo dispatch you do:

dispatchEvent(new YourEvent(YourEvent.SOMETHING_HAPPENED, ob));
James Hay
A typo in the constructor: date should be data: public function YourEvent(type:String, date: Object ...
David
A: 

Hi. In AS3 you can use DataEvent:

ex:

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

Instead of example data, I showed the parameters DataEvent takes.

I hope this helps.

Best regards, RA.