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 />

Creating simple components<br />

Although you are taking the time <strong>to</strong> learn how <strong>to</strong> write code, not everyone likes <strong>to</strong> get his or her<br />

hands dirty. Now you know about variables, condition statements and repeat loops, you are well<br />

on your way <strong>to</strong> becoming a <strong>Flash</strong> expert. But suppose you want <strong>to</strong> let others share your code.<br />

They would want <strong>to</strong> use your code in the simplest way possible, ideally just by dragging a movie<br />

clip out of the library and placing it on the stage. The drag and drop option would not give them<br />

any control over the behaviour of the movie clip, however. They would prefer <strong>to</strong> set up initial<br />

conditions using the minimum of fuss. Take a look at ‘Examples\Chapter09\Fireworks.fla’.<br />

Figure 9.4 Developing the Fireworks project<br />

If you right-click on the star and select the Parameters tab in the Component Properties panel,<br />

you should see the window in Figure 9.4. This window lets the developer set the initial value for<br />

variables in the Component. In this example the variables are ‘gravity’, ‘starTotal’, ‘subStarTotal’,<br />

‘explodeDur’ and ‘recreateTime’. We will look at how the code works later, but for now try<br />

altering the values for ‘starTotal’ and ‘subStarTotal’ and then running the code using Ctrl + Enter.<br />

As you vary the values, the movie runs differently. The movie itself shows a simulation of a<br />

firework, with the number of stars in the firework being set using the ‘starTotal’ clip parameter.<br />

129

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

Saved successfully!

Ooh no, something went wrong!