0

I was wondering if it was possible to create an array of classes in Flash. Is it possible to do like in C++ where you can do the following?

CDog dog[100];
for ( int i = 0; i < 100; i++ ) {
    dog[i] = new Dog();
}

If the above is applicable to flash, the syntax must be different because I was not able to get it working.

I tried using Array, but I think it only works for strings, and integers. I was not able to get it working with classes.

Thanks

4
  • If a class is considered an object, then yes. I want to create an array of my Enemy class so that I can access them via enemy[i]. Commented Aug 17, 2011 at 18:17
  • an object is an instantiated class usually assigned to a var of some sort so you can save the "object" or the var in an element of an array Commented Aug 17, 2011 at 18:22
  • Flash AS3 uses ECMAScript, so the syntax for declaring an array is different than what you're trying to use. Commented Aug 17, 2011 at 18:22
  • Is it even possible to make an array of classes similar to the example I showed above? Commented Aug 17, 2011 at 18:25

1 Answer 1

2

Its been a long long time since AS2 and you might want to consider moving up to AS3 since it is much more OOP orientated.
I haven't touched AS2 in years but the code would look something like.

var aDogs:Array = [];
for ( var i:int = 0; i < 100; i++ ) {
    aDogs[i] = new Dog();
}
Sign up to request clarification or add additional context in comments.

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.