A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Understanding "for" loop iterations

  1. #1
    Senior Member pup100's Avatar
    Join Date
    Oct 2004
    Location
    Close
    Posts
    575

    Understanding "for" loop iterations

    How come every time I run this script:

    code:
    _root.trink_array = ["Carp", "Cod", "Bream"];
    _root.trinity_array = new Array();
    for (var g = 0; g<=2; g++) {
    _root.trinity_array[g] = _root.trink_array[g];
    some_str += "<br>"+_root.trinity_array[g];
    }

    _root.dym_txt.htmlText = some_str;



    I get:

    Undefined
    Carp
    Cod
    Bream

    Where does the “Undefined” come into things? I have only asked the script to fire 3 times so the first time through the text in position [0] in the script “Carp” should be printed out?
    You will know everything when you know you never will.

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    some_str isn't defined before you add the first element. Right before the loop starts add:
    Code:
     var some_str:string = "";
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Senior Member pup100's Avatar
    Join Date
    Oct 2004
    Location
    Close
    Posts
    575
    Many thanks for that samac1068 - There is alaways something that is out to get you in Flash!
    You will know everything when you know you never will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center