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 11: Debugging<br />

5 switch(i){<br />

6 case 0:<br />

7 red();<br />

8 break;<br />

9 case 1:<br />

10 green(random(100), random(100));<br />

11 break;<br />

12 case 2:<br />

13 blue(random(9));<br />

14 break;<br />

15 }<br />

16 count++;<br />

17 }<br />

18 trace("Finished");<br />

19<br />

20 function red(){<br />

21 if (_DEBUG) trace(count + ":red");<br />

22 }<br />

23<br />

24 function green(x, y){<br />

25 if (_DEBUG) trace(count + ":green (" + x + "," + y + ")");<br />

26 }<br />

27<br />

28 function blue(i){<br />

29 if (_DEBUG) trace(count + ":blue " + i);<br />

30 if (i>3){<br />

31 if (_DEBUG) trace("Calling red from blue");<br />

32 red();<br />

33 }<br />

34 }<br />

Listing 11.9 ‘Examples/Chapter11/debug14.fla’<br />

Using a debug layer<br />

When your code runs, it will execute so fast that it becomes extremely difficult <strong>to</strong> work out what is<br />

happening. A debug layer is often useful for more stubborn run-time errors. You create a dynamic<br />

text box on its own layer, which tracks the variable ‘info’, or any other name that you prefer.<br />

Then for each movie clip create a ‘dump’ function. The dump function can be used <strong>to</strong> add some<br />

information <strong>to</strong> the ‘info’ variable.<br />

1 //Frame 1 - Main timeline<br />

2 info = Ball.dump();<br />

161

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

Saved successfully!

Ooh no, something went wrong!