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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With