Adobe Flex 3 Help

Using the global trace() method

You can use the debugger version of Flash Player to capture output from the global trace() method and write that output to the client log file. You can use trace() statements in any ActionScript or MXML file in your application. Because it is a global function, you are not required to import any ActionScript classes packages to use the trace() method.

The following example defines a function that logs the various stages of the Button control's startup life cycle:

<?xml version="1.0"?>
<!-- logging/ButtonLifeCycle.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script><![CDATA[
        private function traceEvent(event:Event):void {
            trace(event.currentTarget + ":" + event.type);
        }
    ]]></mx:Script>

    <mx:Button id="b1" label="Click Me"
        preinitialize="traceEvent(event)"
        initialize="traceEvent(event)" 
        creationComplete="traceEvent(event)"
        updateComplete="traceEvent(event)"
    />

</mx:Application>

The executing SWF file for the previous example is shown below:

The following example shows the output of this simple application:

TraceLifecycle_3.b1:Button:preinitialize
TraceLifecycle_3.b1:Button:initialize
TraceLifecycle_3.b1:Button:creationComplete
TraceLifecycle_3.b1:Button:updateComplete
TraceLifecycle_3.b1:Button:updateComplete
TraceLifecycle_3.b1:Button:updateComplete

Messages that you log by using the trace() method should be Strings. If the output is not a String, use the String(...) String conversion function, or use the object's toString() method, if one is available, before you call the trace() method.

To enable tracing, you must configure the debugger version of Flash Player as described in Configuring the debugger version of Flash Player to record trace() output.