Script Writer wfsWriteSpriteCode Handler
wfsWriteSpriteCode is a tool to be used at authoring time to help you write code that dynamically creates a sprite but doesn't attach any behaviors to it.
wfsWriteSpriteCode generates and returns code that, when run, will create a dynamic sprite and tell you what channel it was created in. You call wfsWriteSpriteCode from the Director Message Window while the movie is running and theSpritenum is instantiated.
The wfsWriteSpriteCode handler is in the "Script Writer" movie script, so you must have a copy of this script in a cast. You must also have a copy of the "1: prepareMovie" script and the "Dynamism" script.
theSpriteNum: is an integer that indicates the sprite that already has theScriptName attached to it.
doNotCreateNewMember: If you don't specify this parameter, the generated code will be such that when it is run, it will create a new member, ie, a copy of the member used by theSpriteNum. If you set doNotCreateNewMember to 1, then when the generated code is run, no new member will be created, ie, the new sprite will use the same member as theSpriteNum.
wfsWriteSpriteCode returns a string that contains a call to wfsCreateSprite which, when copied, pasted into your code, and run, will create a dynamic sprite modelled on the sprite in channel theSpriteNum.
Suppose you want to create a dynamic sprite at run-time. You first construct a model of the sprite on the stage. Suppose it is sprite 5. Suppose also that when the dynamic sprite is created, you want its member to be a copy of the member of sprite 5, ie, you want the dynamic sprite to have a different member than sprite 5 (although a copy of the member of sprite 5). Then you start the movie, navigate to the place in the Score where the model sprite 5 is instantiated and, in the Message Window, type
When you press the Return key, the following output appears in the Message Window:
theNewSpriteNum = wfsCreateSprite(["nu", "Internal", 0, 100, 24, 19, 63, 11]) --parameters: --[member, cast, ink, blend, width, height, locH, locV, doNotCreateNewMember] --If you don't specify a value for doNotCreateNewMember, --then a copy of the member will be created.
You copy this code and paste it into a script. When you run the code, it will create a sprite that uses a copy of member("nu") from the Internal cast. Sprite 5 used member("nu"). The sprite will have ink 0 and blend 100. The width will be 24, the height 19, the locH 63, and the locV 11. Just like sprite 5. The member that has been created will be destroyed at the end of the movie or, when you destroy the sprite using one of the WFS destructors, the member will be destroyed then.
Suppose you wanted to do just like Example 1, but you want the dynamic sprite to not create a new member. Then you would type
and the output would look like this:
theNewSpriteNum = wfsCreateSprite(["nu", "Internal", 0, 100, 24, 19, 63, 11, 1]) --parameters: --[member, cast, ink, blend, width, height, locH, locV, doNotCreateNewMember] --If you don't specify a value for doNotCreateNewMember, --then a copy of the member will be created.
|Script Writer wfsWriteSpriteCode Handler|