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

92 pong:control:5<br />

1 pong:control:9<br />

343 pong:control:10<br />

Event Sounds: 11KHz Mono 16 kbps MP3<br />

Sound name Bytes Format<br />

----------------------- --------- ----------<br />

Pulselec.wav 639 11KHz Mono 16 kbps MP3<br />

Another thing <strong>to</strong> notice in the Movie Report is the use of a small sound file. At less than 1 K the<br />

‘bip’ sound when the ball hits the bat is well worth including.<br />

When you are creating small loader games you want <strong>to</strong> be able <strong>to</strong> easily port them <strong>to</strong> another<br />

game. For this reason a loader game should be a self-contained movie clip. It is best not <strong>to</strong> access<br />

any ‘_root’ level variable because then you can place this game anywhere. A new feature of <strong>Flash</strong><br />

<strong>MX</strong> <strong>2004</strong> is the ability <strong>to</strong> localize a _root <strong>to</strong> within the current document. When loading the<br />

movie clip in<strong>to</strong> a container use the following code:<br />

onClipEvent (load){<br />

this._lockroot =true;<br />

}<br />

This ensures that references <strong>to</strong> _root in the game will refer the timeline of the original document,<br />

not the actual root timeline of the container.swf.<br />

Pong uses seven layers:<br />

sound: Used for the single sound effect, which is embedded inside the movie clip, sfx.<br />

This way it can be triggered easily from code. An alternative method would be<br />

<strong>to</strong> use a ‘Sound’ object, but movie clips work fine.<br />

score: The score is just a dynamic text box that tracks the variable ‘pongScore’.<br />

mask: Used <strong>to</strong> contain the ball within the frame.<br />

ball: Containing the ball movie clip.<br />

board: Containing the board and the bat movie clip.<br />

bg: Containing the background design.<br />

control: Containing all the <strong>ActionScript</strong> that controls the game.<br />

Graphically the game could not be simpler, but the design could easily be changed <strong>to</strong> reflect<br />

the main game for which Pong is being used as just an entertaining loader. The main interest<br />

then is in the coding. For this game all the code is contained in the main timeline. There<br />

are no ‘onClipEvent’s or nested movie clips that contain code. The code is set in four frame<br />

actions.<br />

194

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

Saved successfully!

Ooh no, something went wrong!