ProblemYou need to trace out a message or the value of some data at runtime. SolutionUse the trace function, pass the data to it, run your application, and look for a message in the Console in Eclipse. DiscussionYou 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:
The mm.cfg file allows you to set the following variables:
At a minimum mm.cfg must contain the following enable writing to a file. TraceOutputFileEnable=1 If you want to specify more than one variable, you should place each on a new line, as follows TraceOutputFileEnable=1 TraceOutputFileName=C:\flex.log |