Skip to main content
Participant
April 15, 2023
Answered

Buttons stop working after a few frames

  • April 15, 2023
  • 1 reply
  • 788 views

Hello, Im trying to get some buttons to work in a few frames after frame 164, the buttons on frame 186 and 200 don't work no matter what I try. I can't really find any errors in the console either. My Question is what am I doing wrong and how can I fix these buttons so that I can make more and finish the rest of it.

Before I was using the code snippets but I also tried the add using wizard and none seem to work.

 

Frame 1

/* Stop at This Frame
The timeline will stop/pause at the frame where you insert this code.
Can also be used to stop/pause the timeline of movieclips.
*/

this.stop();

/* Click to Go to Frame and Play
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and continues playback from that frame.
Can be used on the main timeline or on movie clip timelines.

Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
2.Frame numbers in EaselJS start at 0 instead of 1
*/

this.startgame.addEventListener("click", fl_ClickToGoToAndPlayFromFrame_4.bind(this));

function fl_ClickToGoToAndPlayFromFrame_4() {
this.gotoAndPlay(4);
}

var root = this; // here we store a reference to the main timeline

var muteButton = root.muteButton; // here we store a reference to the mute/unmute button

root.toggleMute = function (e)

{
createjs.Sound.muted = !createjs.Sound.muted; // here we invert the sound state (muted/unmuted)

if (createjs.Sound.muted)

root.toggleButton(e.currentTarget, {
out: 2,
over: 2,
down: 2
}); // set the same frame number to the main button states (out, over, and down)

else

root.toggleButton(e.currentTarget, {
out: 0,
over: 1,
down: 2
}); // reset the button frames

};

// convenience/utility method to toggle default button symbols instances on and off

root.toggleButton = function (button, frames)

{
var listeners = button._listeners;

if (!listeners)

return;


for (var key in listeners) {
var listener = listeners[key][0];

if (typeof (listener.outLabel) !== 'undefined')

listener.outLabel = frames.out;

if (typeof (listener.overLabel) !== 'undefined')

listener.overLabel = frames.over;

if (typeof (listener.downLabel) !== 'undefined')

listener.downLabel = frames.down;
}


button.gotoAndStop(frames.out);

};

muteButton.on("mousedown", root.toggleMute); // mouse down listener added to the mute/unmute button

 

Frame 164

/* Stop at This Frame
The timeline will stop/pause at the frame where you insert this code.
Can also be used to stop/pause the timeline of movieclips.
*/

this.stop();

 

/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.

Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
2.Frame numbers in EaselJS start at 0 instead of 1
*/


this.LeftArrow.addEventListener("click", fl_ClickToGoToAndStopAtFrame_186.bind(this));

function fl_ClickToGoToAndStopAtFrame_186() {
this.gotoAndStop(186);
}

 


/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.

Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
2.Frame numbers in EaselJS start at 0 instead of 1
*/


this.RightArrow.addEventListener("click", fl_ClickToGoToAndStopAtFrame_200.bind(this));

function fl_ClickToGoToAndStopAtFrame_200() {
this.gotoAndStop(200);
}

 

Frame 186

var _this = this;
/*
Clicking on the specified symbol instance executes a function.
*/
_this.YL.on('click', function(){
/*
Moves the playhead to the specified frame number in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
*/
_this.gotoAndStop(205);
});


var _this = this;
/*
Clicking on the specified symbol instance executes a function.
*/
_this.YR.on('click', function(){
/*
Moves the playhead to the specified frame number in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
*/
_this.gotoAndStop(208);
});

 

Frame 200

var _this = this;
/*
Clicking on the specified symbol instance executes a function.
*/
_this.door.on('click', function(){
/*
Moves the playhead to the specified frame number in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
*/
_this.gotoAndStop(211);
});

 

This was the console warnings -

    This topic has been closed for replies.
    Correct answer kglad

    I spaced everything out more and tried again with what you said as well, and the buttons still seem to not work after i did this. Can you not set multiple buttons to go to the same frame? I dont know if that is messing up something.


    spacing is irrelevant. it's how you create keyframes and ensuring the problematic button is the same instance on its first keyframs as on the problematic keyframe.

     

    multiple buttons can execute the same listener function.

     

    use console.log to see if your button code is executing at the problematic frame.

    1 reply

    kglad
    Community Expert
    Community Expert
    April 15, 2023

    a common problem is your button losing its instance name by the problematic frame.

     

    i'm assuming you're not seeing any warnings/errors after startup.

    MowyTAuthor
    Participant
    April 15, 2023

    where would that be though because all have an instance name?  and yes I dont see any errors but I still see the warnings they stay the same, they dont seem to be the issue i think.

    kglad
    Community Expert
    Community Expert
    April 15, 2023

    finding the precise problem cause can be impossible to find without scouring your fla history.

     

    fortunately it's a lot easier to fix:

     

    put your button in a layer by itself with no keyframes except the one where your button needs to first appear.

     

    add your code in the first keyframe where your button needs to start working. assign its instance name in that frame if it wasn't addeded in the previous keyframe.

     

    assign your other keyframes if and where needed being careful to not remove the button anywhere until after the last keyframe was created.

     

    test