[haXe] casting attached MovieClips

Yariv Sadan yarivvv at gmail.com
Thu Apr 27 04:11:09 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);

This is especially helpful when you assign the result to an instance
variable, which normally (well, depending on your coding style) has an
explicit type. Example:

class Foo extends MovieClip {
  // ..

  function doStuff() {
    child = doAttach(this, MyClip);
  }
  var child:MyClip;
}

Yariv

>
> That's not so easy. In particular, the type T can't be used as an
> expression in method body right now. However, the following should work:
>
> public static function doAttach<T>(mc:MovieClip,cl : Dynamic) : T {
>     var depth = mc.getNextHighestDepth();
>     var sub = mc.attachMovie(cl.__name__.join("."),"foo"+depth,depth);
>     if( !Std.is(sub,cl) )
>         throw "doAttach failed";
>     return untyped sub;
> }
>
> Then :
>
> doAttach<MyClip>(root,MyClip)
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org
>



More information about the Haxe mailing list