Calling children inside getChildByName / getChild At?
I found out that I can't target a object inside the main MC if I use getChildAt / getChildByName. It will return me
Error #1119: Access of possibly undefined property someProperty through a reference with static t开发者_Go百科ype flash.display:DisplayObject.
I was trying to use something like
this.getChildAt(0).getChildByName("objectName")....
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.
精彩评论