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.
- 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.
- 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.
- 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.
- Copy the following code
addEventListener(Event.ENTER_FRAME, handleNewFrame); //
function handleNewFrame(e:Event){ //
trace("entering the frame "); //
} //
- identify the "Event" and the “Event Handler"
- Test the movie and check the output panel.
- Watch the result of the output panel
- Add “mc1.rotation +=10;”
- Check the movie clip on the screen
- Annotate the code in detail using comments.
- 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()