What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »
In short, no. Vectors might be closer to what you’re looking for. They’re the array’s faster cousin, although it’s important to note that they only accept the object type (and any subclasses of that type) they are originally defined for.
// creates a vector with 5 null elements that will accept sprite objects
var someVector:Vector<Sprite> = new Vector<Sprite>(5);
someVector = new Sprite(); // allowed
someVector = new Point(); // throws a type error because a Point isn't related to a Sprite
someVector = new Sprite(); // throws an out-of-range error
// vs the array created with 5 elements initially
var someArray:Array = new Array(5);
someArray = new Sprite(); // allowed
someArray = new Point(); // allowed, even though it's not related to sprites at all
someArray = new Sprite(); // allowed, the array simply grows to accommodate for some sick reason
// I don't really use arrays in AS3 because I think they suck balls, so if I'm wrong about any of it, someone say so.
> *Originally posted by **[AshAbeAdd](/forums/4/topics/414999?page=1#posts-8204431):***
> Preferably in the prototypes?
It’s not recommended to work with prototypes.
I’m not aware of a way to truly limit the size of an array in C.
Sure enough you set an amount of elements, but nothing prevents you from crossing that line. You’d have to write a function that does this.
In As3, Arrays do not have a set size and grow as you add or remove elements.
Vectors can be set to have a fixed size.
I’d just write a function that keeps the index within your desired boundaries.
If you _really_ wanted to, you could override array, and reject anything added once size reaches a max\_limit variable (which you would add to your new class).
Or as NineFiveThree mentioned, write a function to keep it in bounds,
Or, add a wrapper class that hides the internal array:
public var max_size:int = 0;
private var arr:Array = new Array();
public function addElement(o:Object):Bool
if(arr.length < max_size)
//add any other methods you want/need (pop, get, etc)
But the real question is why would you want to? AS3 along with most higher languages provide dynamic arrays because we’re no longer exposed to the underworkings where you must allocate N\*size bytes for N objects, or where you have to keep track of size, or add a null pointer. If there’s a need to keep it a certain size (ie, only 10 bullets on screen), then it should be the responsibility of the adding code (a shoot function) to check the size (if bullets.size \< 10, shoot()).