getChildByName
and other get child methods return an object of type DisplayObject
. You must cast it appropriately before properties or methods not belonging to display objects. Also bear in mind that these get child methods belong to DisplayObjectContainer
class - so you cannot chain like the way you're trying to do.
var container:DisplayObjectContainer = DisplayObjectContainer(getChildAt(3));
var mc:MovieClip = MovieClip(container.getChildByName("intro_movie"));
mc.gotoAndStop(4);
//or
var container:DisplayObjectContainer = getChildAt(3) as DisplayObjectContainer;
var mc:MovieClip = container.getChildByName("intro_movie") as MovieClip;
mc.gotoAndStop(4);
//or
MovieClip(DisplayObjectContainer(getChildAt(3)).getChildByName("intro_movie")).gotoAndStop(4);
Casting with ClassName(obj)
syntax will throw an error if cast fails; casting with obj as ClassName
returns null without any errors - this might lead to confusions later as it can lead to error 1009 (null reference) at unexpected locations.