Event Handles

Events

Understanding events with Adobe Flash is an enormously important aspect of ActionScript development. To have control to deliver media rich content, ActionScript has to call on an Event. Events communicate between the Mouse, Keyboard and objects that need to share data.

With ActionScript 3.0 there are two distinct roles that are continuously in motion. Broadcasters and Listeners.

  • Broadcasters – informs (tells) Flash what is going on with the Keyboard or the Mouse
  • Listener – Objects that are missing for specific  actions that might be broadcasted by the Mouse (keyboard)

Tutorial 1 – Event Handler

To explore the Broadcaster / Listener interaction, we will create a click handler that can respond to the mouse.

  1. Open Flash
  2. Create a New document 550 x 400 pixel / 30fps
  3. Save File > EventsHandler.fla
  4. Insert > New symbol
    1. Give the symbol the name: RedSquare
    2. Select MovieClip for type
    3. Click Export for ActionScript (RedSquare)
    4. Press OK
    5. If you receive an update message, confirm yes
    6. Add a small square to layer 1 (center to stage)
    7. Return to Scene 1
    8. Rename Layer 1 – Actions
    9. Lock Actions layer
    10. Save file – EventsHandler
    11. Select the first frame on the timeline
    12. Press F9 to open ActionScript panel
    13. Add the following lines of code: (test your movie)

var redSquare = new RedSquare();
redSquare.x = 50;
redSquare.y= 50;
addChild(redSquare);

redSquare.addEventListener (MouseEvent.MOUSE_DOWN,onClick)

function onClick(e:MouseEvent):void {

trace(“The square was clicked.”);

}

Upon testing, the movie the MovieClip calls from the Library by the Export ActionScript name “RedSquare” and is positioned 50 pixels right and 50 pixels down.

I want the square to respond to my mouse. For a response to happen in Adobe Flash, you first have to create a listener that will observe a particular device for events. In this case I what to observe what is happening with the mouse. More so, I want to listen for mouse clicking square.

To expand your mouse event to react when there is a mouse over event.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>