64
Chapter 3: Writing Scripts in Director
Relaying system events with timeout objects
When you create timeout objects that target specific child objects, you enable those child objects
to receive system events. Timeout objects relay these events to their target child objects. The
system events that can be received by child objects include
prepareMovie
,
startMovie
,
stopMovie
,
prepareFrame
, and
exitFrame
. By including handlers for these events in child
objects, you can make the child objects respond to them for whatever purposes you see fit. System
events received by child objects are also received by movie scripts, frame scripts, and other scripts
designed to respond to them.
The following parent script contains a handler for the system event
exitFrame
and a custom
handler
slowDown
.
-- Lingo syntax
property velocity
on new me
velocity = random(55)
end
on exitFrame
velocity = ve 5
end
on slowDown mph
velocity = velocity - mph
end
Associating custom properties with timeout objects
If you want to associate custom properties with a timeout object, you may want to create a
timeout object that uses as a target anything other than a reference to a script instance object.
When you use this technique, the target data becomes data that is associated with the timeout
object, and can be used in your timeout handler.
The following example illustrates using this technique.
-- Lingo syntax
-- initialize a timeout object and pass it a data property list (tData)
-- instead of a reference to a script instance object
tData = [#beta: 0]
tTO = timeout("betaData").new(50,#targetHandler,tData)
-- within a movie script, create the targetHandler handler
on targetHandler (aData)
-- increment and display the beta property
tData.beta = tData.beta + 1
put(tData.beta)
end targetHandler
In the previous example, the
beta
property keeps incrementing. This means that you can
initialize several timeout objects that all call the same movie script handler, and each timeout
object can have its own data list associated with it.
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...