How to Register an Event Listener in Adobe Flash CS4

ActionScript is the programming language that is used to operate Flash animations behind the scenes. It allows developers of Flash based websites to make them more interactive. In order for them to be interactive they must respond to a user’s input, such as clicking a mouse, entering text into a username field and so on. Behind the scenes it is up to the programmer to respond to these items, and that is done through registering an event listener. An event listener tells Flash to listen for when something happens and then respond to it by running the code that is inside the listener fucntion. In this tutorial we are going to regsiter an event listener for the “Mouse Over” event. This occurs when the user takes the mouse pointer and puts it over something. Here is how it is done.

1. Open up a brand new Adobe Flash CS4 (ActionScript 3.0) project.
2.
Step 2

Display the Actions window by selecting “Window” from the main menu, then in the submenu selecting “Actions”. You could also press the “F9″ key on your keyboard.
3.
Step 3

In the Actions code window, type in the following code:
mcCircle.addEventListener(MouseEvent.MOUSE_OVER, mouseOverListener);

This registers the mouse event, mouse over, for the movie clip object called mcCircle. mcCircle can be any move clip object that you draw on your Flash stage. Then this code says when the mouse goes over the mcCircle object, run the function “mouseOverListener”, which we will define in a moment.
4.
Step 4

As you can see in the picture associated with this step, we write our function called “mouseOverListener”. This function will run when the user moves the mousepointer over top of the object mcCircle. The code between the curly braces will execute, and it is there that you can change the color of the object, move it, or a slew of many other things.