Skip to content

Instantly share code, notes, and snippets.

@fljot
Created July 12, 2011 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fljot/1078004 to your computer and use it in GitHub Desktop.
Save fljot/1078004 to your computer and use it in GitHub Desktop.
[AS3] Vector.<*> as argument
var v:Vector.<Sprite> = new Vector.<Sprite>();
trace(v is Vector.<*>);// true
var foo:Vector.<*>;
//foo = v;// Implicit coercion of a value of type __AS3__.vec:Vector.<flash.display:Sprite> to an unrelated type __AS3__.vec:Vector.<*>.
foo = v as Vector.<*>; // OK
var bar:Vector.<Sprite> = foo as Vector.<Sprite>;// OK
genericArgument(v);// true, 0, Hello from genericArgument()
//typedArgument(v);// Implicit coercion of a value of type __AS3__.vec:Vector.<flash.display:Sprite> to an unrelated type __AS3__.vec:Vector.<*>.
function genericArgument(value:*):void
{
var foo:Vector.<*> = value as Vector.<*>;
trace(foo is Vector.<*>, foo.length); // true, 0
trace("Hello from genericArgument()");
}
function typedArgument(value:Vector.<*>):void
{
trace("You won't see this message");
}
@Matan
Copy link

Matan commented Jul 12, 2011

Interesting

@esidegallery
Copy link

Indeed. Thanks for this.

Copy link

ghost commented Jun 18, 2017

This seems to work for Vector. but not Vector.. I guess primitive types don't work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment