调用内getChildByName / getChild在孩子吗? [英] Calling children inside getChildByName / getChild At?

查看:245
本文介绍了调用内getChildByName / getChild在孩子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我不能针对主MC内的对象,如果我使用getChildAt / getChildByName。这将返回我

 错误#1119:的DisplayObject:可能未定义的属性someProperty通过与静态类型flash.display使用参考访问。
 

我是想使用类似

  this.getChildAt(0).getChildByName(对象名)......
 

解决方案

getChildByName 等得到孩子的方法返回类型的对象的DisplayObject 。前适当属性或方法不属于显示对象,则必须强制转换。的同时也要记住,这些让孩子方法属于的DisplayObjectContainer 类 - 所以你不能链就像你正在试图做的方式。

  VAR容器:级DisplayObjectContainer =的DisplayObjectContainer(getChildAt(3));
变种MC:影片剪辑=影片剪辑(container.getChildByName(intro_movie));
mc.gotoAndStop(4);

//要么

VAR容器:级DisplayObjectContainer = getChildAt(3)的DisplayObjectContainer;
变种MC:影片剪辑= container.getChildByName(intro_movie)作为影片剪辑;
mc.gotoAndStop(4);

//要么
影片剪辑(级DisplayObjectContainer(getChildAt(3))getChildByName(intro_movie)。)gotoAndStop(4)。
 

类名(OBJ)如果转换失败语法将抛出一个错误铸造;与铸造OBJ的类名返回没有任何错误空 - 这可能会导致混乱以后,因为它可能会导致错误1009(空引用)在意外的地方

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 type 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.

这篇关于调用内getChildByName / getChild在孩子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆