• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Enable/disable button at certain point in timeline

New Here ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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?

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 31, 2017 Aug 31, 2017

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 soluti

...

Votes

Translate

Translate
Contributor ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

I tried that. still no dice.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines