Copy link to clipboard
Copied
Hello,
I have created a screen which has 2 movieclips which will be used as buttons; they are named button1_mc and button2_mc.
When each button is clicked it should go to frame 2 on the timeline (frame 1 as index starts at 0) of the movieclip to indicate it has been selected and reveal some accompanying text in a movieclip named either reveal1_mc or reveal2_mc. When one button is clicked, it should also set the other button back to frame 1 on its timeline to indicate it is no longer selected, and then hide the corresponding reveal_mc: I have created the "hideAll" function for this purpose.
My code:
var _this=this;
this.hideAll=function(){
this.button1_mc.gotoAndStop(0);
this.button2_mc.gotoAndStop(0);
this.reveal1_mc.visible=false;
this.reveal2_mc.visible=false;
}
this.hideAll();
this.button1_mc.addEventListener("click", reveal1);
function reveal1(){
_this.hideAll();
_this.reveal1_mc.visible=true;
_this.button1_mc.gotoAndStop(1);
}
this.button2_mc.addEventListener("click", reveal2);
function reveal2(){
_this.hideAll();
_this.reveal2_mc.visible=true;
_this.button2_mc.gotoAndStop(1);
}
The problem is that when i run the screen, the buttons automatically start on frame 2 as if they have been clicked (each of these movieclips has this.stop() on each frame too). Once one of the buttons is clicked however it then works as intended.
Can anyone suggest why it would be doing this?
Many thanks.
How about changing your code like this:
this.hideAll=function(){
if (this.button1_mc.currentFrame === 0) {
this.button1_mc.stop();
} else {
this.button1_mc.gotoAndStop(0);
}
if (this.button2_mc.currentFrame === 0) {
this.button2_mc.stop();
} else {
this.button2_mc.gotoAndStop(0);
}
}
Copy link to clipboard
Copied
You're probably trying to control their timelines before they're been fully instantiated. Just put a this.stop() statement in the first frame of each button clip.
Also you aren't using _this in your hideAll function.
Copy link to clipboard
Copied
Hi ClayUUID, thanks for the answer. Unfortunately this doesn't seem to fix the problem; it's almost as if it's ignoring the this.stop() on frame 1 of the button clips.
Another weird thing is that when I write out to the console the buttons currentFrame property it returns 0. (which is frame 1 of the movieclip).
Copy link to clipboard
Copied
Open the dev console when you're testing the page to see if there are any error messages.
Copy link to clipboard
Copied
The timeline of the movieclip is showing it is on frame 1, yet the currentFrame property says its on frame 0.
Copy link to clipboard
Copied
That is how it is with CreateJS. Frame numbers count from 0 when you publish and test.
Copy link to clipboard
Copied
There are no errors when using the F12 developer tools.
I played around with the hideAll function and when I set this.button1_mc.gotoAndStop(1), the timeline shows it is on frame 0, with the currentFrame property showing 1.
Does the indexing start at 1 in some cases?
Copy link to clipboard
Copied
If you gotoAndStop(1) it will go to and stop on the second frame. You can't see the timeline at the time you're testing, but if you mean that you can tell visually that it's the first frame, then there's an error happening.
What does the developer console say in your browser? Are there any errors?
Copy link to clipboard
Copied
Hi Colin,
Thank you for your response. I can visually tell which frame the Movieclip is on as it will turn a different colour. There doesn't seem to by any indication within the developer console of any errors occurring.
I have a demonstration of it here: test
The grey state is when the movieclip is on its first frame. (0 with CreateJS)
The green state is when the movieclip is on its second frame. (1 with CreateJS)
The hideAll() function I have included should initially set the states to grey, but they end up starting green, it all works as intended when one is clicked from thereon in.
Copy link to clipboard
Copied
How about changing your code like this:
this.hideAll=function(){
if (this.button1_mc.currentFrame === 0) {
this.button1_mc.stop();
} else {
this.button1_mc.gotoAndStop(0);
}
if (this.button2_mc.currentFrame === 0) {
this.button2_mc.stop();
} else {
this.button2_mc.gotoAndStop(0);
}
}
Copy link to clipboard
Copied
Many thanks Fumio, that worked!
Thank you all for your help.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now