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, not even Vector. cannot be placed on the right side of the operator.

Is there a way to check if the input argument is a valid vector of any type?

+6
actionscript flash actionscript-3
source share
2 answers

Here is a method that should work. I am sure that there should (of course?) Be the best way out there that does not use strings, but this method should output you.

 /** * 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 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; } 
+4
source share

This also works, although I am very unhappy that I cannot use (vector candidate) reliably.

 private function isVector(candidate : *) : Boolean { var result : Boolean; try { Vector.<*>(candidate).length; result = true; } catch (error : Error) { result = false; } return result; } 
0
source share