I seem to be getting casting failing (returning null) when I have a class that extends a class that extends MovieClip. Here’s an example…

MyWidget extends SimpleButton
SimpleButton extends View
View extends MovieClip

That’s the inheritance chain, SimpleButton and View are some base classes I have written for use in various projects and are not part of the v2 components. Here’s what happens when I try to cast an attachMovie():

var aWidget:MyWidget = MyWidget( attachMovie( MyWidget.LINKAGE,
                    "aWidget", getNextHighestDepth() ) );
trace( aWidget ); // null

That should not be happening of course. Now if we change MyWidget to extend View instead of SimpleButton…

var aWidget:MyWidget = MyWidget( attachMovie( MyWidget.LINKAGE,
                    "aWidget", getNextHighestDepth() ) );
trace( aWidget ); // _level0.blah.aWidget

Now there’s nothing wrong with SimpleButton per se, it does this in other situations, with different inheritance chains (and using v2 component architecture), but it does seem to be failing when the chain gets to a certain length.

The quick fix is to return an instance of MovieClip and cast that afterwards (cheers Dan):

var tempMC:MovieClip = attachMovie( MyWidget.LINKAGE, "aWidget",
                      getNextHighestDepth() );
var aWidget:MyWidget = MyWidget( tempMC );
trace( aWidget ); // _level0.blah.aWidget

I don’t remember this happening in the last few years, before Flash 8 and even whilst Flash 8 has been out, yet it has hit a few of us all at once just recently, it’s as if some update has been released that causes this behaviour, and I know I’ve never had this problem before with the same code methodology. Is anyone else experiencing this, or do you have some extra information on why this happens?