18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

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.

Chapter 18<br />

Using SetVariable() and GetVariable(), it’s possible to pass information to and get information<br />

from a Flash movie. <strong>For</strong> this to work, the Flash movie must have a variable that is watched for a value<br />

change. The simplest way to do this is to create a text field and tie its value to a variable (by selecting<br />

Dynamic Text from the Flash Properties panel and entering the name of the variable). Then, you can get<br />

the value of the variable using GetVariable() and change its value using SetVariable(). Both methods<br />

require the name of the variable in relation to its timeline. So, to access a variable named message<br />

in the main timeline, the first argument for both methods is “/:message”, where “/” represents the<br />

default timeline, the colon indicates a part of the timeline to access, and message is the variable name.<br />

<strong>For</strong> example:<br />

var sOriginalMessage = oFlashMovie.GetVariable(“/:message”);<br />

oFlashMovie.SetVariable(“/:message”, “my new message”);<br />

Some methods also work on a specific timeline in the movie:<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

TCallFrame(timeline, frame_number) — Executes the action in the Eframe that is in the<br />

given position<br />

TCallLabel(timeline, frame_label) — Executes the action in the frame represented by<br />

the given label<br />

TCurrentFrame(timeline) — Returns the position of the current frame in the timeline<br />

TCurrentLabel(timeline) — Returns the label of the current frame in the timeline<br />

TGetProperty(timeline, property_constant) — Returns the value of the property indicated<br />

by the property constant (discussed later) as a string<br />

TGetPropertyAsNumber(timeline, property_constant) — Returns the value of the<br />

property indicated by the property constant as a number<br />

TGotoFrame(timeline, frame_number) — Sets the movie to the frame in the given position<br />

in the timeline<br />

TGotoLabel(timeline, frame_label) — Sets the movie to the frame with the given label<br />

in the timeline<br />

TPlay(timeline) — Plays the movie on the given timeline<br />

TSetProperty(timeline, property_constant, value) — Sets the value of the property<br />

indicated by the property constant as a string<br />

TStopPlay(timeline) — Stops the movie on the given timeline<br />

The TGetProperty(), TGetPropertyAsNumber(), and TSetProperty() methods all use constants to<br />

indicate the property to get or set. Because the constants are only accessible from within Flash, <strong>JavaScript</strong><br />

must always use the numeric value. The constants are listed in the following table:<br />

Flash Constant Value Description<br />

X_POS 0 The x-coordinate of the movie<br />

Y_POS 1 The y-coordinate of the movie<br />

X_SCALE 2 Horizontal scaling<br />

554

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

Saved successfully!

Ooh no, something went wrong!