Tip:
Highlight text to annotate it
X
I mentioned in the last movie that you would set a variable datatype so that you can check
to make sure that your code's running properly. Another way to make sure your code
is running properly is by using something called trace statements. A trace
statement is something that pops up in the Output window,
kind of like a message to yourself. If you're working along in the working files,
I'm in the trace statements file and this is inside of the chapter 2
folder in the Exercise Files. I'm going to go to the first frame of the actions layer
and then open up the Actions panel by pressing Option+F9 on the keyboard. Again that's just
F9 on the PC. And this is the same file that we worked on
in the last exercise, when we did the userName is a string equal to Sammy. If at any point
I want to check the value of this userName, after that semicolon I'm going to press Return
a few times to go down a few lines. And you don't have to really go down that many lines,
I can just go to the second line and write this code.
Personally, I just like to space out my code a little bit so it's easier for me to read.
So on line four I'm going to type trace. It's going to turn blue, because that's a
keyword in Flash. Then an open parentheses, and inside of the parentheses you write the
value that you'd like to trace. So I'm going to write user
and then Name with a capital N, just like I wrote it above.
It's very important to note the casing of my variable on line one.
If I gave it a capital U here and made it look like this, for example, this would give
me a different value. So you want to make sure that your casing is all the same. This
is totally case-sensitive. Alright, so after userName I'm going to do
a close parentheses and a semicolon. And I'll press Cmd+Return and that'll test the movie
and then I get this message in the Output window
that says Sammy. That might not seem like it's too important,
but if you can imagine if we have really complex code, thousands and
thousands of lines of code, and there's one line that's not working properly, but Flash
isn't giving you the problem in the Output window or it's giving you a
problem that you don't understand, by using a trace statement you can check to see if
your code is working. I can also put inside of the trace statement,
if I erase this userName. Let's say I just want to check to see if my
code's working properly. So I'm going to put this trace statement inside of a block of
code to make sure it's running properly. So I put
in quotes: This code is running properly, close quotes.
And Cmd+Return or Ctrl+Enter and test the movie. This code is running properly. Great,
I'm glad this code is running properly. It makes me happy.
So that is how you use a trace statement. It might not make a ton of sense why you'd
use it, but as we go on, you'll see when we write lots and lots of lines of code, trace
statements will be very useful to us to check to see if it's running properly.
In the next movie, I'll explain how to make comments in your code.