Observer mode of eventdispather class

Source: Internet
Author: User

1. To make an object a topic, you must notify other objects when you change the subject so that three usage methods of the eventdispather class can be used:
1. Class static attribute Initialization
Import MX. event. eventdispather;
Class myclass1 {
Public var addeventlistener: function;
Public var removelistener: function;
Private var dispather: function;

Private var eventdispather_mixin = eventdispather. initialize (myclass. Prototype );
Public myclass {
// Init
}
}
2. initialize In the constructor
Import MX. event. eventdispather;
Class myclass {
Public var addeventlistener: function;
Public var removelistener: function;
Private var dispather: function;

Public myclass {
Eventdispather. initialize ();
}
}
3. Include the eventdispather class in combination
Import MX. event. eventdispather;
Class myclass {
Private var eventsrc: object;
Function myclass3 (){
Eventdispather. initialize (eventsrc );
}

Public Function registerview (View ){
Eventsrc. addeventlistener ("change", view );
}

Public Function removeview (View ){
Eventsrc. removeeventlistener ("change", view );
}

Private function onchange (){
VaR eventobj: Object = new object ();
Eventobj.tar get = this;
Eventobj. type = "change ";
Eventsrc. dispathevent (eventobj );
}
}
2. The observer accepts the event
Subject. addeventlistener ("change", this );
Subject. addeventlistener ("click", this );

Public Function Change (eventobj: Object): void {
 
}
Public Function click (eventobj: Object): void {
 
}
Public Function Change (eventobj: Object): void {
Trace (eventobj. parm1 );
Trace (eventobj. parm2 );
}

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.