Logging Using trace() Within an Application

Although not an advanced debugging technique, at one time or another a developer will find a need to trace (also referred to as log) messages from within an application. For this purpose, Flash Player exposes a global trace() method. You can log messages from anywhere within an application simply by calling the trace() method and passing any parameter of type string:

trace("application initialized");

Trace messages are typically displayed by attaching the debugger to an application. With an active FDB debug session, trace messages will be displayed in the console. With Flex Builder, launching a debug session will automatically do this and trace messages will be shown in the Console panel in the debugging perspective (see Figure 18-6).

Flex Builder Debugger Console panel

Figure 18-6. Flex Builder Debugger Console panel

One of the great benefits of using the trace statement in this manner is the ability to receive the messages in real time while an application is running. The trace() method also supports passing in arrays or multiple arguments (rest-style arguments). This can be very useful in dumping data for informational purposes—for example, if you wanted to be able to easily track what children are currently in the Display Child list.

Example 18-1 contains two children. When you click the buttonOne button, the clickHandler() function is called and an array of children is displayed ...

Get Programming Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.