0
votes

How do I initialize a Vector with a class that is stored in a variable?

function initVector(Type:Class) {
    var vec:Vector.<Type> = new Vector.<Type>()
}

initVector(int) gives compiler errors:
1046: Type was not found or was not a compile-time constant: Type.
1120: Access of undefined property Type.

What is the correct way to achieve this?

1

1 Answers

2
votes

As I've researched and explained elsewhere, specifying a non-generic type for your vector will only make a difference, if you're using a number type (int, uint or Number) - those are the performance-optimized variations. All other vectors are really the same generic Vector.<Object> "under the hood" - all type checking is done at compile time, to give you some help with code completion etc., but has absolutely no effect at runtime.

Therefore, unless you will be using only numbers (in which case casting to Number might be an idea), it's absolutely OK to use a Vector.<Object>, or better yet: an Array.