Grimat
Grimat

Reputation: 49

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

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?

Upvotes: 0

Views: 65

Answers (1)

Jan
Jan

Reputation: 445

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();

Upvotes: 2

Related Questions