Compile Flex application without debugging? Optimization for a flexible compiler?

I created a simple test application with the following code

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

When I launch the application, it loads very slowly, which means that "trace" is working. I check the flash player by right-clicking, the debugger option is not enabled.

So I am wondering if it is possible to include the compiler in the trace exception. Otherwise, I have to manually delete all the trace in the program.

Are there other compiler options for optimizing flex applications optimally?

+4
source share
7 answers

Flex has a really weak feature called the logging API (here you can read more at http://livedocs.adobe.com/flex/3/html/logging_09.html ).

Basically, you are logging (tracing) things differently, admittedly, with a bit more code than standard tracing, but that allows you much more 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 have to do is create a trace in the main application file, for example:

 <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 advantages over conventional tracing:

  • You can filter (disable) traces to see only what you want:
    • Or by changing the filter array
    • Or a level to display only error messages or fatal messages
  • You can replace the trace target with any other type of logging protocol, for example.
    • Textfield
    • Text file
+3
source

Use conditional compilation, more here .

In your code:

 CONFIG::debugging { trace(i); } 

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

 -define=CONFIG::debugging,false or -define=CONFIG::debugging,true 
+3
source

You can find / replace the whole project. look for 'trace (' and replace it with '// trace ('. This will be quick and easy enough to undo.

+2
source

The mxmlc debug argument allows you to add or remove debugging features from SWF files. The default debug argument value is false for the command line compiler, but in Flex Builder you need to manually create a non-debug SWF. According to the documentation for the compiler arguments , the debug information added to the SWF includes "line numbers and file names of all source files." There is no mention of trace() function calls, and I don't think there is a way to remove them with a compiler argument, but you can check the linked document for the entire list of available arguments.

+2
source

There are two compiler options that you must set: -debug=false -optimize=true . In Flex Builder or Eclipse, look at Project-> Properties-> Flex Compiler and fill in the box labeled “Additional compiler arguments”.

+2
source

Go to the base directory of your Flex code (and close Flex Builder if it works - it becomes restless if you change things while it works). Run this to change all your trace instructions. I recommend checking the tree on git or something first, and then running diff afterwards (or cp -r tree to make diff -r or something else). The only serious case this will ruin is if you have semicolons inside the trace lines:

 find . -name '*.as' -exec perl -pe 'BEGIN{ undef $/; }s/trace([^;]*);/CONFIG::debugging { trace $1 ; };/smg;' -i {} \; find . -name '*.mxml' -exec perl -pe 'BEGIN{ undef $/; }s/trace([^;]*);/CONFIG::debugging { trace $1 ; };/smg;' -i {} \; 

Then configure in your designers Project-> Properties-> Flex Compiler-> Additional compiler the following:

 -define=CONFIG::debugging,true -define=CONFIG::release,false 

And use:

 CONFIG::release { /* code */ } 

for the sentence "#else". This was the solution I chose after reading this question and answer.

Also be careful:

 if( foo ) { /*code*/ } else CONFIG::debugging { trace("whoops no braces around else-clause"); }; 

those. if you have ONLY one of them in the if or else block or in any block, and its bare block is without bindings, then regardless of whether it is compiled, it will complain.

0
source

Something else you could do is define the logical name debugMode or something in an external .as file somewhere and include this file in any project you use. Then, before any trace statement, you can first check the status of this boolean. This is similar to zdmytriv answer.

I must say that I like edibleCode's answer and look forward to trying to do this for a while.

0
source

All Articles