A simple piece of code that should trace :
- rien
- test
- done!
and I get something completely far away from that,
scenario A :
var __functions_to_execute:Array;
function start():void {
__functions_to_execute =[];
__functions_to_execute.push(futile_trace());
__functions_to_execute.push(futile_trace('test'));
execute_functions();
}
function execute_functions():void {
if(__functions_to_execute.length){
//where shift on this Array remove the first element and returns it
var exec:Function =__functions_to_execute.shift();
exec;
//I tried this too, just in case
//__functions_to_execute[0];
//__functions_to_execute.shift();
} else trace("done!");
}
function futile_trace(_value:String ='rien'):void {
trace(_value);
execute_functions();
}
start();
pretty simple. but the result is :
- rien
- done!
- test
lets add a deprecated function to this and lets change the futile_trace function to :
function futile_trace(_value:String ='rien'):void {
trace(_value);
setTimeout(execute_functions, 0);
}
and then the result is :
- rien
- test
- done!
Ok then, I said to myself, why not, lets change the scope when I call execute_functions, so I tried :
function futile_trace(_value:String ='rien'):void {
trace(_value);
extra_step();
}
function extra_step():void {
execute_functions();
}
guess what was the result?! yeah :
- rien
- done!
- test
so?! Is the trace function that bad? that slow? is it the fact that passing an argument to the function take so much time compare to the other one? I mean… wow!
is there something I can do to avoid this type of weirdness ?
(For the record, my project is not to trace {rien, done and test}… I have 15k lines of codes that react completely differently if I compile them with “Omit trace statements” or not.
Thanks for your input guys.
You are executing the functions and adding their return values to the
__functions_to_executearray, not the functions themselves.Your function
execute_functionsdoesn’t actually do anything. I’ve tried to explain the sequence in-line:Something more like this should behave how you expect. It’s storing in the array function references, along with the arguments that should be passed when the function is called.