User Guide
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).rotation + 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.