A strongly typed collection with several basic types in ActionScript (Vector <T, T>)?
Does ActionScript have any way to handle a strongly typed list with multiple base types?
Am I really looking for something like Vector<T,T> ?
Is it possible?
Or is this the only way to do this by creating my own class that accepts, lets say String and Number in the constructor and create a Vector<T> from this class?
No, not by standard. If the elements are not one of the primitive types, you can create an interface vector or superclasses. For example, a DisplayObjects vector that contains a mixture of MovieClips and Sprites (which both inherit from DisplayObject).
For instance:
var v:Vector.<DisplayObject> = new <DisplayObject>[ new MovieClip(), new Sprite(), new MovieClip() ]; trace(v[0].alpha); // outputs 1 trace(v[0].currentFrame); // error - not a DisplayObject property In this case, the element of vectors will reveal only properties and methods that are based on the type of Vectors. But it is for this reason that you should use vectors, they provide the type of elements that you process.
I do not know your specific case or goal, but I would think why you need a mixed type inside a vector. Your alternative, as you said, would be to create a wrapper class. The example below is far from complete, but the starting point.
class Wrapper { public var _value:*; // should be private with get/set's public function Wrapper(value:*) { if(value is String || value is Number) { _value = value; } } } You cannot do this, so I would go with your suggestion, which is to create a special class containing two properties (e.g. Number, String) and create a vector of this.