Flash CS3 worksheets - Exercise 4

Exercise 4: ENTER_FRAME Event

Objective – learn more about events and handlers to be interactive
Another event is called “Event.ENTER_FRAME”. There are only two things to do.

  1. This event is issued by the Flash runtime engine – you don’t need to do anything. The computer listens to what goes on in the system and your movie. When hears something (e.g. a key press, or a new frame is here to be played) it reports (signals) to the whole system – this is called issuing or triggering an event. There are different types of events and a listener will listen to one specific type of event.
  2. Set up the listener to listen to when a new frame is to be played – whenever a new frame is entered, the system will shout “ENTER(ing) FRAME”. This is called the “ENTER_FRAME” event. Your listener will listen to this and direct the program to the handler.
  3. Set up the handler so that Flash knows what to do when new frame is entered. A handler will handles the event when it occurs by doing something.
  4. Copy the following code
  5. 		addEventListener(Event.ENTER_FRAME, handleNewFrame); //
    		function handleNewFrame(e:Event){ //
    			trace("entering the frame "); //
    
    		} //
  6. identify the "Event" and the “Event Handler"
  7. Test the movie and check the output panel.
  8. Watch the result of the output panel
  9. Add “mc1.rotation +=10;
  10. Check the movie clip on the screen
  11. Annotate the code in detail using comments.
  12. Extension Task: copy and test the following code
    myBox.addEventListener(Event.ENTER_FRAME, moveIt); //
    myBox.x = 250;  //
    function moveIt(evt:Event){ //
        myBox.x += 3; //
        if(myBox.x>500){ //
             myBox.x =250;  //
             } //eof IF
    }  //eof function moveIt()