Stop the main timeline from within a Class function

白昼怎懂夜的黑 提交于 2019-12-13 07:43:27

问题


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
    }

  }

}

回答1:


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
}


来源:https://stackoverflow.com/questions/30220624/stop-the-main-timeline-from-within-a-class-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!