Global trace in your Adobe Flex program

Ability to trace message is very important in building any complex program. 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.


<?xml version="1.0"?>
<!-- logging/ButtonLifeCycle.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete='trace(employees)'>
<mx:Script><![CDATA[
private function traceClick():void {
trace("Entering traceClick");
trace("Exiting traceClick");
}
]]></mx:Script>
<mx:XMLList id="employees">
<employee>
<name>Christina Coenraets</name>
<phone>555-219-2270</phone>
<email>ccoenraets@fictitious.com</email>
<active>true</active>
</employee>
<employee>
<name>Joanne Wall</name>
<phone>555-219-2012</phone>
<email>jwall@fictitious.com</email>
<active>true</active>
</employee>
</mx:XMLList>
<mx:Button id="b1" label="Click Me" click="traceClick()" />
</mx:Application>


You can call trace() method from either the ActionScript or from MXML with either object or String as argument and that message will get traced to the flashlog.txt, if trace is enabled like this



Christina Coenraets
555-219-2270
ccoenraets@fictitious.com
true


Joanne Wall
555-219-2012
jwall@fictitious.com
true

Entering traceClick
Exiting traceClick