热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从Class函数中停止主时间轴-StopthemaintimelinefromwithinaClassfunction

Ineedtostopthemovieatthefirstframeusingafunctionfromaclass,IknowIcanusestop();

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?

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

package {

  public class myApplication {

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

  }

}

1 个解决方案

#1


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

您可以使用root关键字从任何显示对象(位于显示列表中)访问主时间轴:

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.

主时间轴(除非你手动将其他东西添加到位置0的舞台上)将是舞台的第一个孩子。

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
}

推荐阅读
author-avatar
一线天24_226
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有