Package {
Import flash. Events. event;
// Import event class
Public class customevent extends event {
// Declare Custom Event extended Custom Event class as its subclass
Public static const sendflower: String = "sendflower ";
// Declare static constants as Event Type 1
Public static const sendcar: String = "sendcar ";
// Declare static constants as event type 2
Public var info: string;
// Declare variables to store event information, which is also the main reason for using custom events.
// Carry additional information
Public Function customevent (type: String, INF ){
Super (type );
// Call the parent class constructor and set the input parameters as the event type
Info = inf;
// Store the input parameter 2 to Info
}
}
}
// 2. Boys:
Package {
Import flash. Events. eventdispatcher;
// Import the event sender class
Import flash. Events. event;
// Import event class
Public class boy extends eventdispatcher {
// Declare that the boy class extends from the event sender class to become its subclass
Public Function sendflower (){
// Declare the public sending method;
VaR info: String = "Rose ";
// Declare the sending information of the local variable settings
VaR events = new customevent (customevent. sendflower, Info );
// Declare an instance of the New Custom Event class and set the type to the first,
// Store the sent information into the event
This. dispatchevent (events );
// Send this event
}
Public Function sendcar (){
// Declare the public delivery method;
VaR info: String = "millions of sports cars ";
// Declare the sending information of the local variable settings
VaR events = new customevent (customevent. sendcar, Info );
// Declare an instance of the New Custom Event class, and set the type to second,
// Store the sent information into the event
This. dispatchevent (events );
// Send this event
}
}
}
// 3. GIRLS:
Package {
Public class girl {
Public Function replay (Info): void {
Trace (Info );
}
// Declare the public method and make a response
}
}
// 4. Document class:
Package {
Import flash. display. Sprite;
// Import the sprite class
Public class documents extends sprite {
// Declare that the document class is extended from the sprite class
Private VaR _ BOY: boy;
// Declare the private property as the boy type
Private VaR _ GIRL: girl;
// Declare the private property as the girl type
Public Function documents (){
// Constructor
_ Boy = new boy;
// Create a boy instance
_ Girl = new girl;
// Create a girl instance
_ Boy. addeventlistener (customevent. sendflower, _ Hand );
// Add a customevent. sendflower event listener for the boy
_ Boy. addeventlistener (customevent. sendcar, _ Hand );
// Add a customevent. sendcar event listener for the boy
_ Boy. sendcar ();
// Call the boy's delivery method. You can try again to call the boy's sendflower
// Try the method to see if the result is different.
}
Private function _ Hand (E: customevent): void {
// Declare the event Processor
_ Girl. Replay ("I received a handsome guy who sent me:" + e.info );
// Call the girl's replay method.
}
}
}