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.

Chapter 13: Small games <strong>to</strong> keep them loading<br />

using ‘loadVariables’ so the game is very easily adapted. The project file for this example can be<br />

found at ‘Examples/Chapter13/crossword.fla’.<br />

The ‘crossword.txt’ file contains variables of the form<br />

rows: An integer giving the <strong>to</strong>tal number of rows.<br />

rowx: Where x is an integer between 1 and ‘rows’. Each of these is a string<br />

giving the letters for the row. To show a black square, enter a ‘0’<br />

in the appropriate place in the string.<br />

row1=variable00a0 would show as 8 blank squares, 2 black, a blank<br />

and a black.<br />

clue<strong>to</strong>tal: The <strong>to</strong>tal number of clues.<br />

cluex: Where x is an integer between 1 and clue<strong>to</strong>tal. Each of these<br />

indicates the square on which a clue starts.<br />

cluesacross: A string in HTML format.<br />

cluesdown: A string in HTML format.<br />

loaded: Set <strong>to</strong> 1 <strong>to</strong> indicate that loading of the file is complete.<br />

The number of columns, ‘cols’, is determined by getting the length of the first row string. Then<br />

the on-screen clue display ‘cluetext’ is set <strong>to</strong> show the ‘cluesacross’ clues. The crossword is made<br />

up of duplicated movie clips <strong>to</strong> keep the formatting flexible and <strong>to</strong> maintain a small file size. Each<br />

square of the crossword contains a single movie clip that contains just two frames: the first frame<br />

is a black square and the second frame includes an Input text box connected <strong>to</strong> the variable ‘letter’<br />

and a dynamic text box connected <strong>to</strong> the variable ‘clueNum’. Using a little string parsing, the<br />

appropriate frame is chosen. If the current row string contains a ‘0’ at the current column then the<br />

black square, frame one, is shown, if not then frame two is shown.<br />

1 count=0;<br />

2 cols = length(row1);<br />

3 cluetext = cluesacross;<br />

4<br />

5 orgX = 27;<br />

6 orgY = 24;<br />

7<br />

8 var mc:MovieClip;<br />

9<br />

10 for(row=0; row

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

Saved successfully!

Ooh no, something went wrong!