0

Is it possible to make array in as3 like this :

countdowns[bodyID][powerupName] = { time: powerup.getTime(), onRemove: onRemove }; 

I have been trying for hours but no luck.. Thanks

1
  • Could you edit your question with a little more detail about what your powerups and bodies do? It sounds like you might just want an Array of Dictionary objects, but how you fill that depends on what you need to do. Commented Mar 29, 2013 at 16:22

3 Answers 3

2

Sure, but you have to declare each object separately and you have to call index number instead of variable name

Say I have an array of colors with a sub array of types of that color filled with objects describing RGB

var colors:Array = [];
var red:Array = [];
var darkRed:Object = { r : 256, g : 100, b : 100 }
red.push( darkRed ); //darkRed is now part of red
colors.push( red ); //red is now part of colors

To access darkRed, you would do this:

colors[0][0]; //that is darkRed
Sign up to request clarification or add additional context in comments.

Comments

0

I believe this is what you are trying to accomplish :

var countdowns:Array = new Array;
countdowns[bodyID] = new Array;
countdowns[bodyID][powerupName] = { time: powerup.getTime(), onRemove: onRemove };

The second dimension of the countdowns Array is achieved by inserting an array into each element of the first dimension.

Comments

0

While this certainly can be done, but it's possible you're overcomplicating things. Perhaps a single-dimensional Array ob tailored Objects will suit better.

var ob:Object=new Object();
ob.bodyId=bodyId;
ob.powerup=powerup; // direct link to powerup might serve you better!
ob.onRemove=onRemove;
countdowns.push(ob);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.