ActionScript: How to call an objects function within an array?

80 Views Asked by At

In Java it is possible to set the datatype of an array, and by setting the datatype to the object I am using, I can call the methods and variables of that object. For instance:

ArrayList<Object> name = new ArrayList<Object>();
name.add(new Object(variables));
name.get(0).method;

Is there any way I can do this in ActionScript?

1

There are 1 best solutions below

0
On BEST ANSWER

A Vector will let you easily call the functions of your objects which are stored in that vector.

var vector:Vector.<YourObject> = new Vector.<YourObject>();
vector[0].yourObjectFunction();

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html

Alternatively, you can cast the members of an Array to a specific type and then call the functions.

(array[0] as YourObject).yourObjectFunction();