[haXe] casting attached MovieClips

Nicolas Cannasse ncannasse at motion-twin.com
Thu Apr 27 09:15:13 CEST 2006


> Hi Nicolas,
> 
> I actually realized that when you use this technique, you can omit the
> template parameter T when calling doAttach if you assign the result to
> an explicity typed variable. For instance, you can do
> 
> var child:MyClip = doAttach(mc, MyClip);
> 
> but not
> 
> var child = doAttach(mc, MyClip);

You can do both.
But in the second case the "child" will be "Unknown" so you can't use
its methods.

But be careful, since in that case doAttach return type will be inferred
as "MyClip" at first usage. Further call will fail is using a different
type :

var a : MyClip = doAttach(mc,MyClip);
var b : MyOtherClip = doAttach(mc,MyOtherClip);
// error : MyClip should be MyOtherClip

You could set the return type of doAttach to "Dynamic" but in that case
you loose all typing.

Nicolas



More information about the Haxe mailing list