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 );
}