Copy link to clipboard
Copied
Hi again!
Is it just me or the trace() function is severely delaying movie output? I'm quite sure it did not used to be like this.
In this simple example, the output will be immediate:
var i:int, total:int = 999, count:int = 0;
for (i = 0; i < total; i++)
count++;
But if you include a trace statement, at least in my case, the output will be delayed for about 5 seconds.
var i:int, total:int = 999, count:int = 0;
for (i = 0; i < total; i++)
{
count++;
trace(count);
}
For each situation I'm coding a game or app that I need a trace statement inside a loop a huge delaying is happening.
Can someone clarify this?
Thanks!
Copy link to clipboard
Copied
If I do:
var i:int, total:int = 999, count:int = 0;
for (i = 0; i < total; i++){
count++;
}
trace(count);
or:
var i:int, total:int = 999, count:int = 0;
for (i = 0; i < total; i++){
count++;
trace(count);
}
the Output window appears immediately, with either a list ending in 999, or just 999.
I don't know why it would be different for you.
Copy link to clipboard
Copied
Hi! Thanks for the answer.
The problem does happen to me.
Here is a very short video of my situation:
I hope it helps clarifying what is going on.
Copy link to clipboard
Copied
It's the time for the SWF to appear that is longer for you. For me both cases work within a second.
That's on Mac. In Windows 10 I can see the difference in time. I think that the script is finishing before the window appears, which is odd, and it does mean that the trace statements are taking a significant time.
Trace uses Strings, and during playback it's converting an int to a String 999 times. There's some overhead for the playback to figure out that the variable is something that can be converted to a String. I don't know why that is slow on Windows and fast on Mac, but you can reduce the delay a lot by telling the compiler what you have in mind. Try timing this version:
var i:int, total:int = 999, count:int = 0;
for (i = 0; i < total; i++){
count++;
trace(String(count));
}
Copy link to clipboard
Copied
Well, it's really odd that Mac OS and Windows 10 have this huge difference.
Anyway, I tried what you suggested, wrapping the count variable inside of the String method, but the delay persists.
I think it's not really a AS3 problem, because this is already a very simple situation. I used to code way more complex loops with calls to Movie Clips, transformations, and so on and the output used to be the same with or without the trace statements.
I think it's something related to the last updates of Animate CC itself.
Copy link to clipboard
Copied
Yep, using trace a lot slows it down significantly, no matter what you decide to trace. I remember it also being an issue in the Unity editor, last time I used it.
You could try storring each thing you want to trace in an array, and then trace everything with one trace call. Or you could create your own console that's inside the animation.
Copy link to clipboard
Copied
Thanks, RandomlyFish.
But, as discussed above, this doesn't seem to be a matter of AS3 optimization. I can tell you because I've already wrote a lot of way heavier code using not only one but several trace statements and the difference wasn't noticeable on my machines/OS.
But now, the output is taking around 5 seconds on a simple loop.
And even Colin said he saw a difference between Mac and Windows. So, if it was something related to AS3, in both scenarios the SWF should be exported in about the same time. Even if there was some difference, it should be of just a few miliseconds.