Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Actionscript Add Event Listener Example 1

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In this ActionScript Add Event Listener example, two buttons were put on the stage. Both buttons were indentified to listen to an event (Mouse Click Event). Therefore they can trap the event and response according to the reference function.

Flash ActionScript Codes:

// Button enter_btn is identify to listen to a Event
// The type of event is a Mouse Event - Click
// Function (writeText) will be called when the event received
enter_btn.addEventListener(MouseEvent.CLICK, writeText);


// function responsed when Button enter_btn is clicked
function writeText(evt:MouseEvent):void {
// Put the text "Hello World" into the message box
output_txt.text = "Hello World";
}


// Button clear_btn is identify to listen to a Event
// The type of event is a Mouse Event - Click
// Function (clearText) will be called when the event received
clear_btn.addEventListener(MouseEvent.CLICK, clearText);

 

// function responsed when Button clear_btn is clicked
function clearText(evt:MouseEvent):void {
// Empty the message box
output_txt.text = "";

}

Download Flash Source File:

Flash Source File as-add-event-listener-example-1.fla

Remarks:

Actually an object (e.g. Enter Button) can listen to more than one event.