07.12.2012 Views

Adobe Director Basics

Adobe Director Basics

Adobe Director Basics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ADOBE DIRECTOR BASICS<br />

3D: Controlling action<br />

Every frame, <strong>Director</strong> generates a series of events that are sent to all sprites and to the first Movie Script that contains<br />

a handler for the event.<br />

#enterFrame: sent after the image of the frame has been displayed on the screen. All sprites and 3D nodes will<br />

report their new positions accurately.<br />

#exitFrame: sent while the current frame is still on the screen, after the <strong>Director</strong> has registered the new position<br />

of the mouse, but before any adjustments have been made to the position of sprites or 3D nodes<br />

#stepFrame: sent only to scripts and script instances placed on the actorList. See “actorList and #stepFrame events”<br />

on page 426.<br />

#prepareFrame: sent while the current frame is still on the screen but before modifying the positions of sprites and<br />

3D nodes in preparation for displaying the image of the next frame.<br />

Immediately after the #prepareFrame event, <strong>Director</strong> plays sounds, updates the position of 3D nodes, draws<br />

sprites, and performs any transitions or palette effects. When this is complete #enterFrame is then sent again.<br />

Between the #prepareFrame and the following #enterFrame event, the <strong>Director</strong> playback engine is calculating the<br />

value of each pixel to display on the screen. Any code that executes during this period increases the time it takes to<br />

display the next screen.<br />

If the movie is playing at 50 frames per second, each frame will be visible on the screen for 20 milliseconds (= 1000 ms<br />

/ 50 frames per second). The <strong>Director</strong> playback engine will aim to trigger a new #exitFrame event 20 milliseconds<br />

after the previous one.<br />

Between #enterFrame and #exitFrame, the <strong>Director</strong> playback engine is “idle”. It has time to wait until the next frame<br />

is ready to be drawn. During this time, the playback engine can process a large quantity of code without slowing down<br />

the process of redrawing the screen. It is in the period between #enterFrame and #exitFrame that many other events<br />

are generated. These include:<br />

#mouseEnter, #mouseWithin, #mouseDown, #mouseUp, #mouseLeave, #mouseUpOutside<br />

#keyDown, #keyUp<br />

Callbacks from timeOut objects<br />

Callbacks from 3D #timeMS events<br />

enterFrame<br />

If performance is critical to your project, place any lengthy code that needs to be executed on every frame in an on<br />

enterFrame Lingo handler. This is especially true if the code involves updating the appearance or position of sprites<br />

on the screen.<br />

However, an on enterFrame() handler is not good location for code that deals with moving an item in<br />

synchronization with the mouse. The lag between the moment the operating system updates the position of the mouse<br />

pointer and the moment when <strong>Director</strong> updates the Stage is most obvious if the Stage updates are made in an on<br />

enterFrame() handler.<br />

exitFrame<br />

The #exitFrame event is sent just before the process for calculating the new Stage image starts. Any code executed as<br />

the result of an #exitFrame event will delay the update process, in the same way that looking for you keys just before<br />

you leave the house delays your departure. Limit your use of your on exitFrame() handlers to navigational calls to<br />

_movie.go() or _movie.play().<br />

Last updated 8/26/2011<br />

398

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!