You can create your own events and dispatch them, by extending the Event
class.
import flash.events.Event;
class MyEvent extends Event
{
var data: String;
static public var MY_EVENT_TYPE = "my_event_my_event_code";
public function MyEvent(type: String, data: String)
{
this.data = data;
}
override public function clone():Event
{
return new MyEvent(type, data);
}
}
You can then dispatch it and listen to it, using an EventDispatcher
. Note that most flash objects are event dispatchers.
import flash.events.EventDispatcher;
var d = new EventDispatcher();
d.addEventListener(MyEvent.MY_EVENT_TYPE, onType);
function onType(e: MyEvent)
{
trace("I have a string: "+e.data);
}
d.dispatchEvent(new MyEvent(MyEvent.MY_EVENT_TYPE, "Hello events!"));
Note that the clone
method is required if you want to redispatch your event.