Custom events in Flash 3.0

Source: Internet
Author: User

Transferred from the Internet.
Introduce the application of custom events in flash as with the example of boys and girls

 

  
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.

// Carrying 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 input parameter 2 in info

}

}

}

// 2. Boys:
Package {

Import flash. Events. eventdispatcher;

// Import event sender class

Import flash. Events. event;

// Import event class

Public class boy extends eventdispatcher {

// Declare the boy class to expand from the event sender class and become its subclass

Public Function Sendflower (){

// Declare the public sending method;

VaR Info: String = " Rose " ;

// Declare local variables and set sending information

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 to the event

This . Dispatchevent (events );

// Send this event

}

Public Function Sendcar (){

// Declare Public delivery methods;

VaR Info: String = " Millions of sports cars " ;

// Declare local variables and set sending information

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 to the event

This . Dispatchevent (events );

// Send this event

}

}

}

// 3. GIRLS:
Package {
Public class girl {
Public Function Replay (Info ): Void {
Trace (Info );
}
// Declare Public methods and respond
}
}
// 4. Document Type:
Package {

Import flash. display. Sprite;

// Import sprite class

Public class documents extends sprite {

// Declaration Document class extended from sprite class

Private VaR _ BOY: boy;

// Declare the private property as the boy type

Private VaR _ GIRL: girl;

// Declare private property as girl type

Public Function Documents (){

// Constructor

_ Boy = New Boy;

// Create a boy instance

_ Girl = New Girl;

// Create girl instance

_ Boy. addeventlistener (customevent. sendflower, _ Hand );

// Add customevent. sendflower event listening type for boys

_ Boy. addeventlistener (customevent. sendcar, _ Hand );

// Add customevent. sendcar event listening type for boys

_ Boy. sendcar ();

// Call the boy's delivery method. You can try again to call the boy's sendflower

// Try the method to see how the results are different.

}

Private Function _ Hand (E: customevent ): Void {

// Declare event Processor

_ Girl. Replay ( " I received a handsome guy who gave me the following: " + E.info );

// Call the girl's replay method.

}

}

}

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.