简体   繁体   English

AS3在舞台上访问MovieClip?

[英]AS3 Access MovieClip on Stage?

I have a Movie Clip added to my timeline frame 1 and I am trying to figure out how I can access it, I have a button that when I press it I want to restart the movie clip from frame 1 and play. 我在时间轴第1帧中添加了一个影片剪辑,并且试图弄清楚如何访问它,我有一个按钮,当我按下它时,我想从第1帧重新启动影片剪辑并播放。

I exposed it to actionscript with the class of MyMovie. 我使用MyMovie类将其公开给actionscript。

I can create a new instance of it by going 我可以通过以下方式创建它的新实例

var mymovie:MovieClip = new MyMovie();

But I want to access the one I added to the timeline frame, not create a new one. 但是我想访问我添加到时间轴框架中的那个,而不是创建一个新的。 So I can run .gotoAndPlay(1) on that movie clip to restart it. 因此,我可以在该影片剪辑上运行.gotoAndPlay(1)以重新启动它。

Just as you create a variable to reference the object when creating it with code, as in your example: 就像在创建代码时创建引用对象的变量一样,如您的示例所示:

var mymovie:MovieClip = new MyMovie();

you need the same thing for a MovieClip dragged on the time line during authoring time. 在创作期间在时间线上拖动的MovieClip需要相同的内容。 To do this 去做这个

  1. select the MC 选择MC
  2. open the properties panel/properties inspector panel (whatever it's called nowadays) 打开属性面板/属性检查器面板(无论今天是什么)
  3. specify an instance name 指定实例名称

That's pretty much equivalent to creating a variable on the timeline. 这几乎等同于在时间轴上创建变量。 That's because flash automatically declares instance names of Objects as variables on the timeline that you place them on. 这是因为Flash会在放置对象的时间轴上自动将对象的实例名称声明为变量。 This can be disabled in the actionscript settings, but it is enabled by default. 可以在动作脚本设置中禁用此功能,但默认情况下启用。 When you specified the instance name in the properties, you can work with it as if it was a variable (as said, it more or less is a variable) You do not have to declare this variable again with var keyword. 在属性中指定实例名称后,就可以像对待它一样使用它(就像说,它或多或少是一个变量),而不必使用var关键字再次声明此变量。 Just do: 做就是了:

mymovie.gotoAndStop(3);

to see if it works. 看看是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM