Skip to main content
Participant
August 31, 2017
Answered

Enable/disable button at certain point in timeline

  • August 31, 2017
  • 1 reply
  • 2804 views

I've reviewed similar questions but still cannot resolve my specific issue. I have a button that on click goes to a certain point in the timeline and plays. The issue is that while the timeline is playing, this button is still enabled- and if you click it it takes the user back to the first frame. I want to just disable this while it plays, and then reenable once completed.

this.button_4.addEventListener("click", fl_ClickToGoToAndPlayFromFrame_6.bind(this));

function fl_ClickToGoToAndPlayFromFrame_6()

{

this.gotoAndPlay(2);

}

and then on the first frame of the animation, I have created a keyframe and added

button_4.enabled=false;

But this does not work.

Please advise?

    This topic has been closed for replies.
    Correct answer ClayUUID

    Well this is fun... in CreateJS, buttons are created by attaching the ButtonHelper class to a movieclip instance. But in the Animate generated code the class is attached anonymously, like this:

    new cjs.ButtonHelper(this.btn, 0, 1, 1);

    So all the properties of ButtonHelper (like enabled) are completely inaccessible. Good job guys.

    Anyway, the simplest way to disable the button would be to just hide it... this.button_4.visible = false;  ... Can't click something that's not there.

    A more elegant solution would be to fade the button out, indicating it's temporarily not available. For this you could do something like this.button_4.alpha = 0.5; then modify your event code like so...

    function fl_ClickToGoToAndPlayFromFrame_6(evt) {

         if (evt.currentTarget.alpha === 1) {

              this.gotoAndPlay(2);

         }

    }

    Alternatively, you could leave the event code alone and disable with this:

    this.button_4.alpha = 0.5;

    this.button_4.mouseEnabled = false;

    Then enable with this:

    this.button_4.alpha = 1;

    this.button_4.mouseEnabled = true;

    There's lots of ways to do this sort of thing.

    1 reply

    Inspiring
    August 31, 2017

    Did you forget to add "this." before "button_4.enabled=false;" ?

    Participant
    August 31, 2017

    I tried that. still no dice.

    Inspiring
    August 31, 2017

    It should actually be: this.button_4.mouseEnabled = false;