dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Quest: arrays in for-loops

  1. #1
    Member
    Join Date
    Mar 2002
    Posts
    53

    Quest: arrays in for-loops

    I got a problem with enhanceing my code in FlashMX:
    code:
    for (i=0; i<3; i++) {
    P001[i+3] = P001[i];
    }
    for (i=0; i<3; i++) {
    P002[i+3] = P002[i];
    }
    for (i=0; i<3; i++) {
    P003[i+3] = P003[i];
    }



    This code makes copies of P00x[0,1,2] and places those copies in P00x[3,4,5]. Since I will have to go up to about P030 and maybe even higher later I wanted to add another for-loop like this:

    code:
    for (i=1; i<PMax+1; i++) {
    for (j=0; j<3; j++) {
    P00i[j+3] = P00i[j];
    }
    }



    The part marked bold is not valid code of course since I mustn't add the "i" right into the variable-name, but thats exactly the point where I dont know how write the code.
    How can I make that line work, or in another way: how can I make that line dependant on the i-counter and still tell Flash, that "P00" and the counter-i toghether form the name of the variable?
    Last edited by thebluerider; 10-26-2005 at 03:36 PM.

  2. #2
    Junior Member
    Join Date
    Oct 2005
    Posts
    13
    One way to do it would be to create a multi-dimensional array, rather than having 30 discrete arrays.

    code:

    P00 = new Array(PMAX);
    for (i=0; i<PMAX; i++) {
    P00[i] = new Array(6);
    }

    ...

    for (i=0; i<PMax; i++) {
    for (j=0; j<3; j++) {
    P00[i][j+3] = P00[i][j];
    }
    }


  3. #3
    Junior Member
    Join Date
    Oct 2005
    Posts
    13
    Another way to do it - in your existing code - would be like this:
    code:

    for (i=1; i<PMax+1; i++) {
    for (j=0; j<3; j++) {
    this["P00"+i][j+3] = this["P00"+i][j];
    }
    }


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