简体   繁体   中英

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.

I exposed it to actionscript with the class of MyMovie.

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.

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. To do this

  1. select the 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. 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. Just do:

mymovie.gotoAndStop(3);

to see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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