views:

58

answers:

2

In the following code:

var a:Vector.<int> ...
var b:Vector.<String> ...
var c:Vector.<uint> ...
var c:Vector.<MyOwnClass> ...

function verifyArrayLike(arr:*):Boolean
{
   return (arr is Array || arr is Vector)
}

verifyArrayLike(a);
verifyArrayLike(b);
...

What I'm looking for is something like _var is Vector.<*>

But Vector.<*> is not a valid expression, even Vector. can not be placed at the right side of operators.

Is there a way to check if an input argument is a valid Vector of any type?

A: 

I don't quite understand, I'm afraid. arr is Vector is a valid expression, at least for me (compiling with flex SDK 4).
What have you tried and what kind of errors do you get?

greetz
back2dos

back2dos
+1  A: 

Here's a method that should work. I'm confident there must (surely?) be a better way out there that doesn't use strings, but this method should tide you over.

/**
 * Finds out if an object is a generic Vector.
 * It works because the value returned for getQualifiedClassName(a vector) 
 * is "__AS3__.vec::Vector.<the vector's type>".
 * @param object Object Any object.
 * @return Boolean True if the object is a generic Vector, false otherwise.
 */
function isVector(object:Object):Boolean 
{
    var class_name:String = getQualifiedClassName(object);
    return class_name.indexOf("__AS3__.vec::Vector.") === 0;
}
danyal
very nice code!
ty