ActionScript is particularly weak in handling loops. A simple loop like this exits prematurely.
for (var i:uint = 0; i < 12000; i++) {
t.appendText(i);
}
Any workaround please? (This loop is perfectly fine in Java.)
there's no problem with that loop in actionscript either.
you should change i to an int (it's more efficient) and you may need to increase your script time limit (file>publish settings>swf) if the host computer cannot complete that within your default time limit.
p.s. if you're using strict mode you'll need to cast or convert i to a string to append it to your textfield.
Hi kglad,
No problem? It can't be. I've tried this for days already.
int or Number were tried. Time limit was set to 1 hour... It's a big piece of software. Everything is OK, except the loop.
Cast i to String? You expert indeed. I removed + ' ' before the post.
I'm very curious if you can show the entire 12000 in the textfield? I don't believe that. (12000 is perhaps where things start going wrong.) Try it, please.
kglad, thanks for your prompt reply. I really appreciate that.
i don't see a problem. here's the code i used. the for-loop completes in just under 6 seconds on my computer:
var startTime:int=getTimer()
t.text=""
for (var i:int = 0; i < 12000; i++) {
t.appendText(i.toString());
}
trace(getTimer()-startTime); // 5931
p.s. here's the populated textfield though i'm not sure if there's a problem with your host computer that will cause a problem: www.kglad.com/Files/forums/main_1.html
I simplified the scenario.
Actually, there are nested loops. There is complex string and array manipulation in between. The program works fine. But when the loop counters get big, it ends prematurely.
I wrote an identical version in Java. It ends gracefully though Java runs slowly.
I am using the Java version. I will take a hard look at the AS version again, since that loop works on your computer.
kglad, thank you very much for all the trouble.
kglad, of course your replies are helpful. They boost my confidence in AS.
I begin to suspect my host computer. It's ordinary Windows XP and Flash Player 10. I will upload my .swf to Internet and test it from cyber cafe and my local library.
And if 1 day I figure out the root cause, I post it here.
Thanks again kglad, a kind soul indeed. I used to answer other people's queries on forums.
North America
Europe, Middle East and Africa
Asia Pacific