Originally also studied eventdispatcher, but recently used more, did not think so easy to use, do not define so many global variables.
I do not do too much explanation, want to understand the students to see help, I just tell you how to define their own events, and you can immediately use these code to define their own events.
Look at the code below:
First we want to import Eventdispatcherimport mx.events.eventdispatcher;class testevent extends movieclip{ function testevent ( {////Initialize Eventdispatcher.initialize in constructor (this); } Defines these three method function Dispatchevent () {} function AddEventListener () {} function RemoveEventListener () {} function Sendok () { Define event OnSend var eventobj1:object = {target:this,type: "OnSend"}; Dispatchevent (eventObj1); Trace ("OK");//define Event OnComplete var eventobj2:object = {target:this,type: "OnComplete"}; Dispatchevent (EVENTOBJ2); }
How to use our events? Look down!
Create a new FLA and enter the following code:
Do you remember the UI-built event handler, which is similar to the UI set-up, is AddEventListener and Removoeeventlistener.
var testobj:testevent = new TestEvent (); var eventobj1:object = new Object (); eventobj1.onsend = function (obj) { trace ( ' Type: ' +obj.type;} var eventobj2:object = new Object (); eventobj2.oncomplete = function (obj) { trace ("type:" +obj.type);} Testobj.addeventlistener ("OnSend", eventObj1); Testobj.addeventlistener ("OnComplete", EventObj2); Testobj.sendok () ;
Ok! Go and define your events.