Copy link to clipboard
Copied
I have a layer containing a button named "Skip" that holds the code:
Skip.addEventListener(MouseEvent.CLICK,releaseHandler);
function releaseHandler(e:MouseEvent):void {
gotoAndPlay(153);
}
I would like the skip button to go to and play frame 153, but this code only makes it go to the frame of that specific layer. However, I have all the other animated elements in movieclips inside of seperate layers. Before I had them in seperate layers but without each being a movieclip, and the button worked fine, but now how can I change the code to reflect the changes I made?
you need to know either the path from timeline that contains your code to the movieclip timeline that you want to control or from the main timeline to your movieclip timeline that you want to control.
so, if the movieclip you want to control is on the main timeline and has instance name mc, this code will work from any timeline:
MovieClip(root).mc.gotoAndPlay(153);
this is not good coding and will only work if mc exists when the code executes.
Copy link to clipboard
Copied
that code should still work, but you can't test movieclips by scrubbing the timeline. use the test environment (ctrl-enter, by default).
Copy link to clipboard
Copied
I tested it in both Flash and HTML since it's the button that needs correcting. I'll give a simple rundown if it'll help:
Let's say I have my skip button on layer one and a movieclip that has an animation of a square moving from the left side to the right side on layer two. In my situation, the code I currently have only plays frame 153 of the "skip button layer" and not the square layer which I want it to. But let's say I go into the movie clip and copy and paste the layer out so that it's part of the main timeline, that's when the button works, however I need it to be a movieclip for independent animations and that's why I need the correction.
I tried adding event listeners to all other movieclips but the button still isn't doing anything, I tried the MovieClip(root) and (parent) codes too without any results.
Message was edited by: LessHeroes
Copy link to clipboard
Copied
i'm not sure what you're seeing but your analysis of what's occuring is incorrect: all layers are played (though guide layers are handled differntly than all other layers). layers don't even exist in the swf. they are just used for depth ordering of on-stage objects and a few other things.
if your movieclip is on a keyframe (in any layer) at frame 153 you will see your movieclip's timeline play (under typical circumstances).
Copy link to clipboard
Copied
My movieclips are all on frame 1 and start playing then, and the point where I want to go to and play from is frame 153 of all movieclips. The problem is that the button isn't going to frame 153, I doubt it's even doing anything, which is why I think the code is in need of a correction even though it seems correct.
Copy link to clipboard
Copied
you must direct each and every movieclip that you want to change frames. if you do not specifically reference a movieclip (like in your message 1), the timeline that contains the code is directed to frame 153.
if your movieclip has instance name, mc and you want to direct it to its frame 153, use:
mc.gotoAndPlay(153);
Copy link to clipboard
Copied
I tried that as well before, but it returned me with a 1120: Access of undefined property. The code is placed within a movieclip within a movieclip and the movieclips that are being addressed are all on the main timeline, so I tried the MovieClip(this.parent.parent).gotoAndPlay(153) as well as MovieClip(this.parent.parent).movieclipname.gotoAndPlay(153) and still didn't get it to work.
Copy link to clipboard
Copied
you need to know either the path from timeline that contains your code to the movieclip timeline that you want to control or from the main timeline to your movieclip timeline that you want to control.
so, if the movieclip you want to control is on the main timeline and has instance name mc, this code will work from any timeline:
MovieClip(root).mc.gotoAndPlay(153);
this is not good coding and will only work if mc exists when the code executes.
Copy link to clipboard
Copied
Thank you, I didn't even think to try root all this time, but that did it for me.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now