Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Flex application without debug? Optimisation options for flex compiler?

I have created a simple test application with the following code

var i : int;
for (i=0; i<3000000; i++){
   trace(i);
}

When I run the application, it's very slow to load, which means the "trace" is running. I check the flash player by right-clicking, the debugger option is not enable.

So I wonder if there is an option to put in compiler to exclude the trace. Otherwise, I have to remove manually all the trace in the program.

Are there any other options of compiler to optimize the flex application in a maximum way?

like image 377
maoanz Avatar asked Dec 18 '22 08:12

maoanz


2 Answers

There is a really sweet feature built into Flex called the logging API (you can read more about it here http://livedocs.adobe.com/flex/3/html/logging_09.html).

Basically, you log (trace) things in a different way, admittedly with slightly more code than a standard trace, but it allows you much greater flexibility. This is an example:

import mx.logging.Log;
Log.getLogger("com.edibleCode.logDemo").info("This is some info");
Log.getLogger("com.edibleCode.logDemo").error("This is an error");

Then all you need to do is create a trace target in your main application file, something like:

<mx:TraceTarget id="logTarget" fieldSeparator=" - " includeCategory="true" includeLevel="true" includeTime="true">

            <mx:filters>
                <mx:Array>
                    <mx:String>*</mx:String>
                </mx:Array>
            </mx:filters>

            <!--
            0 = ALL, 2 = DEBUG, 4 = INFO, 6 = WARN, 8 = ERROR, 1000 = FATAL
            -->
            <mx:level>0</mx:level>

    </mx:TraceTarget>

And register the trace with:

Log.addTarget(logTarget);

This provides several benefits over the normal trace:

  • You can filter (turn off) traces to only see what you want:
    • Either by modifying the filters array
    • Or the level to show only error or fatal messages
  • You can replace the trace target with any other type of logging interface, e.g.
    • A TextField
    • A text file
like image 139
edibleCode Avatar answered Apr 27 '23 20:04

edibleCode


Use conditional compilation, more here.

In your code set:

CONFIG::debugging { 
    trace(i);
}

Then go to Project->Properties->Flex Compiler and add

-define=CONFIG::debugging,false
or
-define=CONFIG::debugging,true
like image 35
tefozi Avatar answered Apr 27 '23 20:04

tefozi