Object-oriented programming with Lingo
61
Using scriptInstanceList
You can use the
scriptInstanceList
property to dynamically add new behaviors to a sprite.
Normally,
scriptInstanceList
is the list of behavior instances created from the behavior
initializers defined in the Score. If you add child objects created from parent scripts to this list, the
child objects receive the messages sent to other behaviors.
For example, the following statement adds a child object to the
scriptInstanceList
property
of sprite 10:
-- Lingo syntax
add(sprite(10).scriptInstanceList, new(script "rotation", 10))
The following is a possible parent script that the previous statement refers to:
-- Lingo syntax parent script "rotation"
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
on prepareFrame me
sprite(spriteNum).rotation = sprite(spriteNum).ro 1
end
When a child object is added to
scriptInstanceList
, you must initialize the child object’s
spriteNum
property. Typically, you do this from a parameter passed in to the
on new
handler.
Note:
The
beginSprite
message is not sent to dynamically added child objects.
For reference information on
scriptInstanceList
, see
“scriptInstanceList” on page 975
.
Using actorList
You can set up a special list of child objects (or any other objects) that receives its own message
each time the playhead enters a frame or the
updateStage()
method updates the Stage.
The special list is
actorList
, which contains only objects that have been explicitly added to
the list.
The message is the
stepFrame
message that is sent only when the playhead enters a frame or the
updateStage()
command is used.
Objects in
actorList
receive a
stepFrame
message instead of an
enterFrame
message at each
frame. If the objects have an
on stepFrame
handler available, the script in the handler runs each
time the playhead enters a new frame or the
updateStage()
method updates the Stage.
Some possible uses of
actorList
and
stepFrame
are to animate child objects that are used as
sprites or to update a counter that tracks the number of times the playhead enters a frame.
An
on enterFrame
handler could achieve the same results, but the
actorList
property and
stepFrame
handler are optimized for performance in Director. Objects in
actorList
respond
more efficiently to
stepFrame
messages than to
enterFrame
messages or custom messages sent
after an
updateStage()
method.
Содержание DIRECTOR MX 2004-DIRECTOR SCRIPTING
Страница 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Страница 48: ...48 Chapter 2 Director Scripting Essentials...
Страница 100: ...100 Chapter 4 Debugging Scripts in Director...
Страница 118: ...118 Chapter 5 Director Core Objects...
Страница 594: ...594 Chapter 12 Methods...
Страница 684: ...684 Chapter 14 Properties See also DVD...
Страница 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Страница 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Страница 889: ...netPresent 889 _player alert Sorry the Network Support Xtras could not be found See also Player...
Страница 1102: ...1102 Chapter 14 Properties...