Groups » Flash Maniacs » Topics » Event Listeners (AS 3.0)

Listing 1-1 of 1    1   of  1
Author Message
Flash Mod

M/22
,
Instant Message
Send Message
Reply with this quote Reply to this Post Posted:  May 13, 2007 8:15 AM
This tutorial will discuss how to use the addEventListener comand.

This is basically the replacement for onRelease, onRollOver, onRollOut, etc...

Now to actually set up the mouse event takes a little more action script then normal, but once you do that, its all the same as 2.0.

Here is the example we will be using:

function starClick (evt:MouseEvent):void {
     this.gotoAndStop (10);
}

star_btn.addEventListener (MouseEvent.CLICK, starClick);

First you must set up a function. This function will be called when the mouse event happens. Then give the function a name.
Then inside the parenthesis, we have to give the function a parameter. This will be stating that the function will happen on an event data typed as a MouseEvent. Then we know there will be not output for this function so we strict type it to void.

When the function is called the action of this time line going to and stopping on frame 10 will happen. Nothing new there.

Now we have to point to our button which has an instance name of star_btn. Then instead of doing .onRelease we have to make make an .addEventListener.

Inside this event listener, we are saying that it is a MouseEvent and that even type is when the mouse is CLICKed. When this event happens, the function starClick that we created earlier will be called.

The most common mouse events are:

CLICK

DOUBLE_CLICK

MOUSE_DOWN

MOUSE_MOVE

MOUSE_OUT

MOUSE_OVER

MOUSE_UP

MOUSE_WHEEL

ROLL_OUT

ROLL_OVER



That is all there is to creating an addEventListener rather then an onRelease, onPress, etc...!!!

Defining what the function will do when called is all basically the same as AS 2.0.

addEventListener.fla

Thank you for reading this tutorial. I hope you find it very helpful with your flash animations. For any help with this tutorial or questions, please post only in this forum thread.

~Flash Mods
Listing 1-1 of 1    1   of  1

dspPostReplies v29