eHow launches Android app: Get the best of eHow on the go.

How To

How to Create an Event Listener in Flash CS4

Member
By Mike
User-Submitted Article
(1 Ratings)
Create an Event Listener in Flash CS4
Create an Event Listener in Flash CS4

Flash has come a long way since the days of simple animation. With Action Script 3.0 it is become a more usable piece of software in creating very robust websites.

One of the advancements is the ability to create event listeners. These are pieces of code that will execute when some type of event or action occurs.

In this tutorial I am going to create an object and then create the event called mouse over. This means when the user moves the mouse cursor over the object something will happen, in this case, we will just print some text in the trace window.

Difficulty: Easy
Instructions

Things You'll Need:

  • Flash CS4
  1. Step 1

    Launch Flash CS4 and create a new ActionScript 3.0 Flash file.

  2. Step 2

    Draw an object on the stage. I have drawn a rectangle.

  3. Step 3

    Select the object you drew on the stage and press the F8 button. You will see the "Convert to window" screen appear. Give the object a name, in my case I am calling it Rectangle, make the type "Move Clip" and make sure you check on the box that reads "Export for ActionScript", then click the ok button.

  4. Step 4

    We now need to give our rectangle object a name. Press CTRL+F3 to display the properties panel as shown in the picture associated with this step. Notice how I gave my movie clip object an instance name called "mcRectangle".

  5. Step 5

    Click on the first frame in the timeline and then press the F9 key to bring up the action script window.

  6. Step 6

    In the picture associated with this step, you see the action script code needed to complete this tutorial. So go ahead and copy what it is written.

    The first line of code:
    mcRectangle.addEventListener(MouseEvent.MOUSE_OVER, mcRectangle_MouseOver)
    Creates a mouse over event listener for the object mcRectangle. This says when the mouse cursor moves over mcRectangle then execute the function "mcRectangle_MouseOver".

    Lines 2 through handle the actual mouse event fucntion with a paramter of "e". On line 3 we see where we send our output to the trace window.

  7. Step 7

    Run the program by pressing the CTRL+ENTER keys and move your mouse cursor over the object.

Comments  

lostmarble said

Flag This Comment

on 7/21/2009 Thanks Mike. Nice article.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics