从类函数中停止主时间线 [英] Stop the main timeline from within a Class function

查看:273
本文介绍了从类函数中停止主时间线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在第一帧使用一个类的函数停止电影,我知道我可以使用stop();或this.stop();但是如何从类函数中停止主时间线?

 包{b 
$ b public class myApplication {

public function myApplication(stageRoot:Stage){
stop(); //这不起作用
this.stop(); //这不起作用




$ $ $ c $ $ $ $ $ $您可以通过使用根来从任何显示对象(即在显示列表中)访问主时间轴。 code $>关键字:

  MovieClip(root).stop(); 

如果你的班级不在显示列表中(看起来是你的情况)我们需要传递一个参考。我看到你正在传递一个阶段引用,所以你可以使用:

$ p $ MovieClip(stage.getChildAt(0))。停止();主要的时间线(除非你手动添加了其他的东西到位置0的阶段)将是阶段的第一个孩子。



所以你的代码看起来像这样:

  public function myApplication(stageRoot:Stage){
MovieClip(stageRoot.getChildAt(0))。stop();





$ b

或者,如果根据您的评论,您只需将根时间线传递给: p>

  public function myApplication(timelineRoot:MovieClip){
timelineRoot.stop();

// stage可以通过做:timelineRoot.stage
}


I need to stop the movie at the first frame using a function from a class, I know I can use stop(); or this.stop(); but how do I stop the main timeline from within a class function?

package {

  public class myApplication {

    public function myApplication(stageRoot:Stage) {
       stop(); // this doesn't work
       this.stop(); // this doesn't work either
    }

  }

}

解决方案

You can access the main timeline from any display object (that is on the display list) by using the root keyword:

MovieClip(root).stop();

If your class is not on the display list (as appears to be your case), then you'll need to pass in a reference to something that is. I see you are passing in a stage reference, so you could use that:

MovieClip(stage.getChildAt(0)).stop();

The main timeline (unless you've manually added something else to the stage at position 0) will be the first child of the stage.

So you code would then look like this:

public function myApplication(stageRoot:Stage) {
   MovieClip(stageRoot.getChildAt(0)).stop();
}

OR, if based off your comments you just pass root timeline in:

public function myApplication(timelineRoot:MovieClip){
    timelineRoot.stop();

    //stage can be had by doing:  timelineRoot.stage
}

这篇关于从类函数中停止主时间线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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