Skip navigation
moksc
Currently Being Moderated

AS loops

Sep 18, 2012 9:12 PM

Tags: #as #loops

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.)

 
Replies
  • kglad
    62,004 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 18, 2012 10:48 PM   in reply to moksc

    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.

     
    |
    Mark as:
  • kglad
    62,004 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 6:27 AM   in reply to moksc

    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

     
    |
    Mark as:
  • kglad
    62,004 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 1:19 PM   in reply to moksc

    you're welcome.

     

    p.s.  please mark helpful/correct responses, if there are any.

     
    |
    Mark as:
  • kglad
    62,004 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 9:10 PM   in reply to moksc

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points