Stop the main timeline from within a Class functio

2019-09-18 04:35发布

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条回答
等我变得足够好
2楼-- · 2019-09-18 05:02

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
}
查看更多
登录 后发表回答