Accessibility

ActionScript cookbook beta

Handle button interactions

Problem Summary

You need to determine when the user interacts with a button.

Solution Summary

Listen for events broadcast by the button.

Explanation

ActionScript 2

function onButtonRelease():Void
{
   trace("button was clicked");
}

function onButtonRollOver():Void
{
   trace("button was moused over");
}

my_button.onRelease = onButtonRelease;
my_button.onRollOver = onButtonRollOver;

ActionScript 3

function onButtonClick(event:MouseEvent):void
{
   trace("button was clicked");
}

function onMouseOver(event:MouseEvent):void
{
   trace("button was moused over");
}

my_button.addEventListener(MouseEvent.CLICK, onButtonClick);
my_button.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);

Note: Both examples assume there is a button symbol instance named "my_button" on the same timeline as the code.