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

How To

How to Create an Event Listener in Adobe Flash CS4

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

Adobe Flash CS4 has come a long way from its early days as a simple animation tool. Now combined with the programming language ActionScript 3.0 you can do some pretty amazing things. In this tutorial I am going to show you how to create an event listener. An event is something that occurs such as the user clicking the mouse and the listener is the function that will execute when that event takes place. Here is how you create an event listener in Adobe Flash CS4 with ActionScript 3.0.

Difficulty: Moderately Easy
Instructions

Things You'll Need:

  • Adobe Flash CS4
  1. Step 1

    Launch Adobe Flash CS4 and select Create New Flash File (Action Script 3.0).

  2. Step 2
     

    Rename your layer "actions" by double clicking the layer name in your layers panel.

  3. Step 3
     

    Now we start creating our code. Click on frame 1 on the actions layer, then select "Window" from the main menu at the top, and then select "Actions". This will bring up the action script window.

  4. Step 4
     

    Type in the code as it is shown in the picture associated with this step. The first line reads stop();. That tells flash to not loop our program when we run it.
    The second line:
    stage.addEventListener(MouseEvent.CLICK,buttonClickListener);

    registers a mouse click event called "buttonClickListener" to the stage. So everytime we click the mouse on the stage the event buttonClickListener will execute.

  5. Step 5
     

    Now we write the code of our event listener in this case "buttonClickeListener". This function says that when the user clicks the mouse we will print the words "button clicked" in our output window. To see the code you have to look at the associated picture with this step.

  6. Step 6
    Final Results
     
    Final Results

    In the function the parameter "e" can be named anything you want but it must be of type "MouseEvent". We set our return value for our function to "void" since we do not need or expect a return value.

    Now run the program by clicking the "CTRL+ENTER" keys on your keyboard, and then start clickin on the stage.

Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
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