A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Assigning a value to multiple array elements

  1. #1
    Member
    Join Date
    Nov 2004
    Posts
    48

    Assigning a value to multiple array elements

    I currently have a two-dimensional array that represents a gameboard. I have functions that assign values to every element in that array. I currently use two "for" loops to go through the array like so:

    for (i=0; i<11; i++) {
    for (j=0; j<11; j++) {
    GameBoardArray[i][j] = 1;

    }
    }

    I was wondering if there was some kind of operator that I could use that would do this with one line of code, such as:

    GameBoardArray[?][?] = 1;

    Is this possible in Actionscript?

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    not really - you can use the "in" iterator and skip the curlies to save some keystrokes tho
    Code:
    a=GameBoardArray;
    for(b in a)for(c in a[b])a[b][c]=1;
    or a little fancier, a recursive proto
    Code:
    Array.prototype.assign=function(a){for(var i=this.length;i--;)this[i]=this[i].assign?this[i].assign(a):a;return this;}
    
    
    var bob=[100,200,300,[1,2,3],[[[[[[["A"]]]]],this,getTimer()]]];
    trace(bob);
    bob.assign("molasses");
    trace(bob);

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