Does Flash support 2D Arrays?
Printable View
Does Flash support 2D Arrays?
yes it does.
Is the syntax:
inv = new Array();
inv[item][ammount] = 3;
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:
Then repeat the last three lines for each item.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
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:
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 = 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
}
If that doesn't work, I'm stumped.Code:inv[0].item = value
_root.itemPrintOut = inv[0].item