6

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?

kp11
  • 2,055
  • 6
  • 22
  • 25

3 Answers3

20

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, 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 yo dispatch you do:

dispatchEvent(new YourEvent(YourEvent.SOMETHING_HAPPENED, ob));
James Hay
  • 12,580
  • 8
  • 44
  • 67
  • A typo in the constructor: date should be data: public function YourEvent(type:String, date: Object ... – David Aug 25 '10 at 13:32
5

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.

0

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

dirkgently
  • 108,024
  • 16
  • 131
  • 187