Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Macromedia Flash Trace Command

Macromedia Flash Trace Command


For most people who learn how to program, the first thing they learn is to display "Hello World!" words. So today, I suggest we should learn how to display a "Hello World!" words in Macromedia flash as well.

In flash actionscript, to display texts in the output window, we use trace() command. It is one of the essential tools for debugging in the flash movies. It comes very handy when we want to know what's going on in runtime.

Let's us look at an example:

Note: for all the flash examples below, open a new flash document and on the first frame paste the flash actionscript into action panel. Press Ctrl + Enter to test the flash movie. If you do not see an Output Window display for any reason, press F2 to open it.

trace("Hello World!");

This actionscript will display the phrase "Hello World!" in the output window.

How about when we want to display some dynamic variable? Try this:

name = "your name";
trace("Hello " + name + ", welcome to CambodiaXP.com");

This actionscript will display the phrase "Hello your name, welcome to CambodiaXP.com" in the Output Window.

Plus ( + ) is an operator. What it does is it joins the text together. In our case, the text are "Hello ", "your name" and ", welcome to CambodiaXP.com". Note that the variable 'name' has been replaced by the text "your name".

Below is our last example. It shows you how trace() command being used as debugging tool.

myNum = Math.random();
if (myNum<0.5) {
trace("Number is less than 0.5 and the number is "+myNum);
} else {
trace("Number is more than 0.5 and the number is "+myNum);
}

This flash actionscript will display one of the two phrases depending on the value stored in the variable 'myNum'. For your interest, 'myNum' variable is getting the value from the Math.random() method which will generate a random floating-point number from 0 to 0.999999999.

Flash actionscript trace() command is very useful command, so I hope this tutorial will help you to kick start on more advance used of trace() flash actionscript command.



Author's URL: CambodiaXP.com
Final results of our readers
New!
Passed through all the steps? Share your result!
Your result will be premoderated.
Please make sure you choose the right image.
 
 



Captcha

*Required fileds
Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website. More Flash Tutorials: Featured Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

No comments yet...
Add comments to "Macromedia Flash Trace Command"

Captcha