[英]Can't Access MovieClips' Timelines through stage.getChildAt
I've simplified my problem down to this self explanatory code. 我将问题简化为这个自我解释的代码。 Why doesn't each Movie Clip on the stage go to frame two?
为什么舞台上的每个影片剪辑都不会进入第二帧? The error occurs on line six.
该错误发生在第六行。
stage.addEventListener(Event.ENTER_FRAME,update);
function update(e:Event)
{
for (var i:int=0; i<stage.numChildren; i++)
{
stage.getChildAt(i).gotoAndPlay(2);//error here
}
}
Thank you for your help. 谢谢您的帮助。
The getChildAt
method returns an instance of DisplayObject
(see documentation ), but you're trying to call a method on the instance which is a member of the MovieClip
class. getChildAt
方法返回DisplayObject
的实例(请参阅文档 ),但是您试图在该实例上调用方法,该实例是MovieClip
类的成员。 You need to cast the instance returned to the correct type: 您需要将实例强制转换为正确的类型:
stage.addEventListener(Event.ENTER_FRAME,update);
function update(e:Event)
{
for (var i:int=0; i<stage.numChildren; i++)
{
MovieClip(stage.getChildAt(i)).gotoAndPlay(2); // cast instance to MovieClip
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.