Things you have to do to program a button in AS 3.0

1. You need to DECLARE a function with what the button is going to do,

2. You need to name the instance of the button, so AS3 can find it
(Select the instance on Stage-Name it in the Properties window).

3. You need to DECLARE an event listener (addEventListener), connected in the code to the button-instance-name, using dot syntax).
The addEventListenercontains the information about:

What state will trigger an action (ROLLOVER, CLICK...)This is called MouseEvent,
What action to trigger (the name of the function from step 1).

Code for a button named play_btn, that needs to move the timeline to frame n 5 and let it play when the user clicks on it,

function goNow(event:MouseEvent)
{
gotoAndPlay(5);
}

play_btn.addEventListener(MouseEvent.CLICK, goNow);

 

Mouse Events are always refered to in AS3 in Uppercase. The events defined for the MouseEvent class are:

CLICK,
DOUBLE_CLICK
MOUSE_OVER
MOUSE_DOWN
MOUSE_UP
MOUSE_MOVE
MOUSE_OUT
MOUSE_WHEEL
ROLL_OVER
ROLL_OUT

Most of the actions we will be working with in this class are going to be Ttimeline navigation-commands.
(commands that move the playhead across the timeline).
There are a number of simple to use functions already made by Flash to navigate the timeline.
Those ready-made functions are called METHODS.

Most common METHODS Don't need a parameter

stop();

play();

nextFrame();

previousFrame();


Need a parameter
(information written inside the parenthesis)


gotoAndPlay();

gotoAndStop();