Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 516
teleme.io Avatar asked Apr 23 '10 10:04

teleme.io


1 Answers

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;
}
like image 114
Danyal Aytekin Avatar answered Sep 30 '22 18:09

Danyal Aytekin