02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

The first parameter in the ‘sendsprite’ method is the layer number for the sprite, and the second<br />

parameter is the name of a function for an attached behaviour for the sprite. Direc<strong>to</strong>r uses a syntax<br />

that prefixes the name of a function with the ‘#’ character <strong>to</strong> denote a symbol. The 3D world has<br />

a script behaviour attached that contains the code that will be called<br />

on s<strong>to</strong>pmotion<br />

moveZ = 0<br />

rotY = 0<br />

end<br />

In this example the code is used <strong>to</strong> set the value of two variables that are used <strong>to</strong> update the<br />

position of the camera in the 3D world for each step of the timer. Direc<strong>to</strong>r uses the ‘enterFrame’<br />

event for each beat of the timer:<br />

on enterFrame<br />

vec = cam.transform.position<br />

x = integer(vec.x/10)<br />

y = integer(vec.y/10)<br />

z = integer(vec.z/10)<br />

str = string(x) & ":" & y & ":" & z<br />

sprite(1).setVariable("position", str)<br />

vec = cam.transform.rotation<br />

x = integer(vec.x)<br />

y = integer(vec.y)<br />

z = integer(vec.z)<br />

str = string(x) & ":" & y & ":" & z<br />

sprite(1).setVariable("orientation", str)<br />

cam.rotate(0, rotY, 0)<br />

cam.translate(0, 0, moveZ)<br />

end<br />

The ‘enterFrame’ event is used <strong>to</strong> update the value of a string containing information about the<br />

camera position and orientation. This is sent <strong>to</strong> <strong>Flash</strong> using the syntax:<br />

sprite(n).setVariable(variableName, variableValue)<br />

where n is the layer where the <strong>Flash</strong> sprite resides, variableName is the name of the <strong>Flash</strong> variable<br />

and variableValue is string value <strong>to</strong> set. If you have a variable within a movie clip that you need <strong>to</strong><br />

set then you can use the following syntax:<br />

392<br />

sprite(n).telltarget(clipName)<br />

sprite(n).setVariable(variableName, variableValue)<br />

sprite(n).endtelltarget()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!