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.

Chapter 9: Using loops<br />

Two examples <strong>to</strong> help you understand<br />

As usual, examples are the best way <strong>to</strong> learn. Boot up your machine and open ‘Examples\<br />

Chapter09\Loops01.fla’. Here is a very simple program that uses the Bucket from the previous<br />

chapter <strong>to</strong> show how loops can work.<br />

Figure 9.1 The Loops01 project<br />

Figure 9.1 shows the ‘Loops01’ project in development. There are just five layers; any frame<br />

actions are placed on the usual ‘Control’ layer. There is only one frame in this timeline, and the<br />

action for frame one is just <strong>to</strong> set a global variable ‘numBuckets’ <strong>to</strong> the value 1, since we have just<br />

one bucket on screen, then the second line is the <strong>ActionScript</strong> command ‘s<strong>to</strong>p( )’.<br />

numBuckets = 1;<br />

s<strong>to</strong>p();<br />

The code <strong>to</strong> move and update the Bucket is all inside the Bucket clip or as an ‘onClipEvent’<br />

action for the clip. If you are interested then click on the Bucket and view the Action panel by<br />

pressing F9. The code we are interested in can be found by clicking the ‘Duplicate’ but<strong>to</strong>n and<br />

125

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

Saved successfully!

Ooh no, something went wrong!