A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: 2D Arrays

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    190
    Does Flash support 2D Arrays?

  2. #2
    curmudgeon swampy's Avatar
    Join Date
    Jan 2001
    Location
    [wakey]
    Posts
    2,775
    yes it does.

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    190
    Is the syntax:

    inv = new Array();
    inv[item][ammount] = 3;

  4. #4
    Registered User
    Join Date
    Nov 2000
    Posts
    136
    This is my understanding:

    Arrays can have content of any data type--string, number, any object, other arrays, etc. If I understand correctly what you're trying to do, you could do something like this:

    Code:
    inv = new Array(); 
    // inv[0] is the first item, with a subarray for the name 
    // of the item and the price
    inv[0] = new Array();
    inv[0][0] = itemName
    inv[0][1] = itemPrice
    Then repeat the last three lines for each item.


    Now, I'm not sure the last two lines are the right way to access an array within an array. If that doesn't work, you could try a different method. That is, instead of having arrays nested in the "inv" array, you could have objects nested in the "inv" array. You would then assign each object two properties, "item" and "price". That would look something like this:

    Code:
    inv = new Array(); 
    // inv[0] is the first item, with a subarray for the name 
    // of the item and the price
    inv[0] = new Object();
    inv[0] = {
         item: value
         price: value
         any other property/value pairs you want
    }
    This object acts like a movie clip, where each property is a variable inside it. That means the properties can also be accessed and assigned with standard dot-notation, such as this:

    Code:
    inv[0].item = value
    _root.itemPrintOut = inv[0].item
    If that doesn't work, I'm stumped.


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