customizing events with Eventdispatcher

Source: Internet
Author: User
Tags define

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.