ENTER_FRAME Event Listener

Add Event Listener

Let's start by opening the ball_addChild.fla we've been working on. We may want to go back in case we ruin it, so click File > Save As and name our new file: ball_move

When we left off, our ActionScript window looked like this:

var ball1:ball = new ball();

Copy the following statement and Paste it at the bottom of the actionScript:


Pay particular attention to the color coding... the only element not in bright blue is moveBall:

We've seen EventListeners before, when we worked with buttons. Instead of asking Flash to "listen" for a button click, we're listening for a different kind of event: ENTER_FRAME. The ENTER_FRAME event takes place at all times the file is running, and we're using it to call the function moveBall. ENTER_FRAME runs at the frame rate: If the frame rate is set to 24fps, the moveBall function will repeat 24 times every second.

OK, since the moveBall function doesn't exist, we need to create it!