addEventListener: Basic Button

There are many ways to create buttons. Here is an example of a simple EventListenter:

//Activates the "fDown"function
bButton.addEventListener(MouseEvent.MOUSE_DOWN, fDown);
//Activates the "fUp"function
bButton.addEventListener(MouseEvent.MOUSE_UP, fUp);

//activated by "MOUSE_DOWN" listener
function fDown(evt:MouseEvent):void {
//changes the message to "Mouse Down"
tMessage.text="Mouse Down";
}

//activated by "MOUSE_UP" listener
function fUp(evt:MouseEvent):void {
//Clears the message
tMessage.text="";
}

Example

Get Adobe Flash player

Leave a Reply