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 2

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This ActionScript Add Event Listener example is similar to the previous tutorial. The only difference is that the Enter Button is listening to two events (Event MOUSE DOWN and Event MOUSE UP)

When the Enter Button receive that MOUSE DOWN event, the function writeText will be called. While the function clearText will be called when the Enter Button receive that MOUSE UP event.

Flash ActionScript Codes:

// Button enter_btn is identify to listen to two Events
// The type of event is a Mouse Event DOWN and Mouse Event UP
// Function (writeText) will be called when MOUSE_DOWN event received
// Function (clearText) will be called when MOUSE_UP event received
enter_btn.addEventListener(MouseEvent.MOUSE_DOWN, writeText);
enter_btn.addEventListener(MouseEvent.MOUSE_UP, clearText);


// 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-2.fla

Remarks:

This is the end of Flash ActionScript event tutorial.