Using Director > Parent Scripts > Using scriptInstanceList |
![]() ![]() ![]() |
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, this statement adds a child object to the scriptInstanceList
property of sprite 10:
add sprite(10).scriptInstanceList, new(script "rotation", 10)
This is a possible parent script that the statement refers to:
-- 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.
![]() ![]() ![]() |