ActionScript 3.0 Cookbook: Chapter 1: ActionScript Basics
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
var keyword the first time they are used
in a script. You can assign a value to a variable using an
equal sign (=),
which is also known as the assignment operator. If a variable is
declared outside a class method, it is a class variable. Class variables, or
properties, can have access modifiers,
public, private,
protected, or
internal. A private variable can only be
accessed from within the class itself, whereas public variables
can be accessed by objects of another class. Protected variables can be accessed from
an instance of the class or an instance of any subclass, and
internal variables can be accessed by
any class within the same package. If no access modifier is
specified, it defaults to internal.x property, which can be both
tested and set. On the other hand, a text field's length property, which indicates the
number of characters in the field, can be tested but cannot be
set directly (it can be affected indirectly, however, by adding
or removing text from the field).;).
This book uses the terms statement
and action interchangeably. // and terminate automatically at the
end of the current line. Multiline comments begin with /* and are terminated with */.This excerpt is from ActionScript 3.0 Cookbook. Well before Ajax and Windows Presentation Foundation, Macromedia Flash provided the first method for building "rich" web pages. Now, Adobe is making Flash a full-fledged development environment, and learning ActionScript 3.0 is key. That's a challenge for even the most experienced Flash developer. This Cookbook offers more than 300 solutions to solve a wide range of coding dilemmas, so you can learn to work with the new version right away.
Don't worry if you don't understand all the specifics. You can use each recipe's solution without understanding the technical details, and this primer should help you understand the terminology.
Recipes 1.13 and 1.14
You need to trace out a message or the value of some data at runtime.
Use the trace function, pass the data to it, run your application, and look for a message in the Console in Eclipse.
You can trace out a message, the value of a variable, or just about any other data using trace, just as you would in earlier versions of ActionScript. Some examples:
trace("Hello, world");
trace(userName);
trace("My name is " + userName + ".");
Since the .swf is now launched in an external browser, it might seem that there is no way to capture the output of these trace statements. Fortunately, it is possible, and this functionality has been built in to Flex Builder 2 via the Console view. The Console view is the equivalent of the Output panel in the Flash IDE. Although it is not open when you first start Eclipse, it appears when needed.
The only requirement to using trace and the Console view is that you use Debug to test your application. Doing so includes extra features in the .swf that allows it to communicate back to the Console behind the scenes and pass any messages you trace. The following class creates a variable, assigns a value to it, and then traces it, along with some other string data:
package {
import flash.display.Sprite;
public class ExampleApplication extends Sprite {
public function ExampleApplication( ) {
var userName:String = "Bill Smith";
trace("My name is " + userName + ".");
}
}
}
Now when you debug your application, it launches as usual in your default browser. Close the browser and switch back to Eclipse. You will see that the Console view is now open and has displayed the data you traced out.
When you launch the debug version of an application, you must have the debug version of Flash Player installed. If you don't have the debug version of Flash Player, you'll see an error message notifying you, and you'll have to download and install it from http://www.adobe.com/support/flashplayer/downloads.html.
Additionally, the debug version of Flash Player can write trace content to a file. The file that Flash Player uses is determined by mm.cfg, a file that is stored in the following locations:
| Operating system | Location |
|---|---|
| Windows XP | C:\\Documents and Settings\\[user name]\\mm.cfg |
| Windows 2000 | C:\\mm.cfg |
| Mac OS X | MacHD:Library:Application Support:macromedia:mm.cfg |
The mm.cfg file allows you to set the following variables:
TraceOutputFileEnable TraceOutputFileName ErrorReportingEnable MaxWarnings