Refreshing the Screen with updateAfterEvent
As we learned
earlier in Section 10.12, the
mouseDown
,
mouseUp
,
mouseMove
,
keyDown
, and
keyUp
event handlers
are executed immediately upon the occurrence of those events.
Immediately means immediately—
even if the
event in question occurs between the rendering of frames.
This immediacy can give a movie great responsiveness, but that
responsiveness can easily be lost. By default, the visual effects of
a mouseDown
, mouseUp
,
mouseMove
, keyDown
, or
keyUp
event handler are not physically rendered
by the Flash Player until the next available frame is rendered. To
really see this in action, create a single-frame movie with a frame
rate of 1 frame per second, and place a movie clip with the following
code on stage:
onClipEvent (mouseDown) { _x += 2; }
Then, test the movie and click the mouse as fast as you can. You’ll see that all your clicks are registered, but the movie clip moves only once per second. So, if you click 6 times between frames, the clip will move 12 pixels to the right when the next frame is rendered. If you click 3 times, the clip will move 6 pixels. Each execution of the mouseDown handler is registered between frames, but the results are displayed only when each frame is rendered. This can have dramatic effects on certain forms of interactivity.
Fortunately, we can force Flash to immediately render any visual change that takes place during a user-input event handler without waiting for the next frame to come around. We simply ...
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.