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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

function loaded(success){<br />

if (success){<br />

go<strong>to</strong>AndS<strong>to</strong>p("LoadedOK");<br />

}else{<br />

go<strong>to</strong>AndS<strong>to</strong>p("LoadFailed");<br />

}<br />

}<br />

Chapter 12: Using external files<br />

Firstly a new LoadVars object is created and called ‘lv’. The callback that will be used whenever<br />

the object has loaded some variables is set <strong>to</strong> the function called ‘loaded’. A LoadVars object passes<br />

a single parameter in<strong>to</strong> the onLoad function that indicates whether the load was successful or not.<br />

We can use this parameter <strong>to</strong> adjust the behaviour of the movie. We do not have <strong>to</strong> call this<br />

parameter ‘success’; it is simply a Boolean variable (true or false) and can have whatever name we<br />

choose.<br />

If the load is successful then the variables are not at the root of the movie, instead they are all<br />

inside the LoadVars object. For example if the file ‘myvariables.txt’ contained:<br />

Apple=1&Pear=2&Orange=3<br />

then the object lv would contain:<br />

lv.Apples = 1<br />

lv.Pear = 2<br />

lv.Orange = 3<br />

Chapters 14, 21 and 22 give more information about communicating with databases using <strong>Flash</strong> and<br />

ASP pages.<br />

Using JavaScript on the current page<br />

<strong>Flash</strong> can communicate with the current page using any JavaScript function that is placed on the<br />

page using the <strong>ActionScript</strong> function ‘fscommand’. This function takes two parameters: the first is<br />

a string that can be used as a command name, the second is used for arguments. Because Internet<br />

Explorer uses VBScript as the default scripting language you need <strong>to</strong> put a VBScript version on<br />

the page and a JavaScript version. In example ‘Examples\Chapter12\fscommand.html’ we use a<br />

simple <strong>Flash</strong> movie ‘fscommand.swf ’ which is created with the project file ‘fscommand.fla’.<br />

The ‘Set’ but<strong>to</strong>n calls a function ‘onSet’ which contains the following code:<br />

function onSet(){<br />

fscommand("setSpan", str);<br />

}<br />

179

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

Saved successfully!

Ooh no, something went wrong!