Click to go to the home page.

See Also
"Script Writer" Movie Script
wfsCreateSprite
wfsAttachBehavior

 

Site Nav

css drop down menu by Css3Menu.com

Script Writer wfsWriteSpriteAndBehaviorCode Handler

wfsWriteSpriteAndBehaviorCode (theSpriteNum, doNotCreateNewMember)

Click to go to top of section. Function

wfsWriteSpriteAndBehaviorCode is a tool to be used at authoring time to help you write code that dynamically creates a sprite and attaches behaviors to it. You create a model of the sprite you want to finally create dynamically, point wfsWriteSpriteAndBehaviorCode at it, and wfsWriteSpriteAndBehaviorCode generates the code you can use to create the sprite dynamically. This saves you from having to configure most parameters in the calls you make to wfsCreateSprite and wfsAttachBehavior to do the job.

wfsWriteSpriteAndBehaviorCode generates and returns code that, when run, will create a dynamic sprite, tell you what channel it was created in, and attach to it the same behaviors as are attached to theSpriteNum. You call wfsWriteSpriteAndBehaviorCode from the Director Message Window while the movie is running and theSpritenum is instantiated.

The wfsWriteSpriteAndBehaviorCode 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.

Click to go to top of section. Parameters

theSpriteNum: is an integer that indicates the spritenum of the model sprite.

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.

Click to go to top of section. Return Value

wfsWriteSpriteAndBehaviorCode 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. The string also contains as many calls to wfsAttachBehavior as there are behaviors attached to theSpritenum. The calls to wfsAttachBehavior initialize any properties in any getPropertyDescriptionList handlers to the initial values that the model sprite properties were initialized to.

Click to go to top of section. Examples

EXAMPLE 1

Suppose you want to create a dynamic sprite at run-time. You first construct a model of the sprite on the stage, and attach the behaviors to it. Suppose it is 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

put wfsWriteSpriteAndBehaviorCode(5)

or

put wfsWriteSpriteAndBehaviorCode(5, 1)

if you want the new sprite to have a member that is a copy of the member of sprite 5 rather than the very same member as sprite 5. When you press the Return key, the following sort of output appears in the Message Window:

--CREATE A SPRITE AND INIT IT:*******************************************
theNewSpriteNum = wfsCreateSprite(["window handle", "1: Intro", 36, 100, 398, 21, 356, 16])
--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.
theScript=wfsAttachBehavior("4: Window/Menu Element", theNewSpritenum, \
  
[#pWFSManagerName: theManagerName, #pWFSManagerSpriteNum: theManagerSpriteNum])
theScript=wfsAttachBehavior("6: Handle", theNewSpritenum, [#pWFSConstrainingWindow: "stage"])
theScript=wfsAttachBehavior("Cursor Control", theNewSpritenum, [#pWFSTypicalSettings: "Drag and Drop"])

The line that calls wfsCreateSprite creates the sprite. No value is specified for the doNotCreateNewMember parameter, so a new member will be created.

The below line attaches the "4: Window/Menu Element" behavior to theNewSpritenum. You have to replace "theManagerName" with the name of the manager you want it to be an element of. You also have to replace "theManagerSpritenum" with the spritenum of the manager you want theNewSpritenum to be an element of.

The return value "theScript" is a reference to the script, so that after the below line is tweaked and run, theScript.pWFSManagerName will tell you the name of the sprite's manager, for instance.

theScript=wfsAttachBehavior("4: Window/Menu Element", theNewSpritenum, \
  
[#pWFSManagerName: theManagerName, #pWFSManagerSpriteNum: theManagerSpriteNum])

The below line attaches the "6: Handle" behavior to theNewSpritenum. We can see that the "6: Handle" behavior on sprite 5 was apparently configured so that the window is to be constrained to the stage.

theScript=wfsAttachBehavior("6: Handle", theNewSpritenum, [#pWFSConstrainingWindow: "stage"])

The below line attaches the "Cursor Control" behavior to theNewSpritenum. The "Cursor Control" behavior on sprite 5 was apparently configured to "Drag and Drop".

theScript=wfsAttachBehavior("Cursor Control", theNewSpritenum, [#pWFSTypicalSettings: "Drag and Drop"])

You copy this code and paste it into a script. And make the tweaks mentioned above. When you run the tweaked code, it will create a sprite that uses member("window handle") from the "1: Intro" cast. Sprite 5 used member("window handle"). The sprite will have ink 36 and blend 100. The width will be 398, the height 21, the locH 356, and the locV 16. Just like sprite 5.

In general, if you see

#pSomeProperty: someVariable

in the output of wfsWriteSpriteAndBehaviorCode, you need to replace "someVariable" with a specific value or define that variable before the call to wfsAttachBehavior.

 

Click to go to the home pageScript Writer wfsWriteSpriteAndBehaviorCode Handler