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

Strange buttons behavior

Community Beginner ,
May 10, 2018 May 10, 2018

Hi All,

I am still working on the same project that I talked about on my previous post. I am just getting frustrated because when I set an action for a button It rarely does the expected on the first attempt. For example on frame 1, I click the directory button to display my combobox, that works fine, the I want to close the combobox so I click close, and it works fine, but if I then repeat the operation and click the directory button it jumps two frames..

Or if I click the number one button on the lower menu, it is set to go to frame 0 and it is going to frame 1. I mean, they dont do the expected action, I don´t know if it has to do because the order in which you place the code on the Actions panel is relevant, but, it is very difficult to work when you fix something somewhere and something else then breaks..

I leave here the fla file in case someone has the time.

this.btndirectory.addEventListener("click", showlist.bind(this));

Dropbox - editable_Canvas.fla

Thanks,

433
Translate
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
Community Expert ,
May 14, 2018 May 14, 2018

Hi.

When using a timeline as screens, always check if a object already has a event listener before you add one. Because if not, you are going to add multiple listeners to a single object when you navigate back and forth.

Like this:

if (!this.btndown1.hasEventListener("click"))

    this.btndown1.addEventListener("click", sol.bind(this));

Also, it seems to me you're using gotoAndPlay to change the frames of the main timeline. Is this what you really want?

Regards,

JC

Translate
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
Community Beginner ,
May 15, 2018 May 15, 2018

Hi,

Many thanks for your help, I am really stuck at this point.

Yeah well there are objects (buttons) that are used throughout the entire animation. For example btndirectory and btnclose are used to trigger the combobox effect and they just have to go on frame forward or one frame backwards. But yeah they are assigned several event listeners because depending on the frame where you are the button will redirect you either one frame backwards or one frame forward.

I guess the only way to have each object just one event listener assigned is to give the objects unique names throughout the entire animation.

I am using the gotoAndPlay to move on the timeline and also to make sure the animation starts when moving to the desired frame. Specially for the navigation buttons, like the row with numbers on the bottom and the combolist on the combobox. Also for the btnadvance button  which moves forward one animation per click.

For the btndirectory and btnclose I am looking for something else  than gotoAndPlay because those are not navigation buttons, those buttons just move one frame forward or backwards. any ideas?

Thanks and regards,

Fco.

Translate
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
Community Expert ,
May 15, 2018 May 15, 2018

Hi.

What I mean by several listeners is when you add a listener to an object with the same handler function over and over again.

Say, for example, you have a button on the first frame that sends the timeline to the next frame everytime it receives a click, like this:

this.button.on("click", function(e)

{

    this.gotoAndStop(this.currentFrame + 1);

}.bind(this));

If you go back to the first frame once, the button will advance the timeline by 2 frames because it now has two listeners.

If you go back to the first frame twice, the button will advance the timeline by 3 frames, because it now has three listeners.

If you go back to the first frame three times, the button will advance the timeline by 4 frames, because it now has four listeners.

And so on.

This is what I mean and this is why it is important to check if the object already has a listener before adding one.

About the gotoAndPlay, I just pointed out to make sure that this is what you really want.

Translate
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
Community Beginner ,
May 15, 2018 May 15, 2018
LATEST

Hi,

I am so desperate with this animation. Every time I touch something then something else breaks, its like a never ending story. I don´t know what´s going on, you either have to be a createjs expert or otherwise  it is impossible to set this up correctly. I don´t understand the behavior of the buttons, I dont know why do I get so many errors at once on the dev console, and if I fix them, some other will show up.

I don't understand why are those code snippets there if they actually don`t work. I mean its true that I have like 50 buttons or maybe more but I haven´t I used the correct code snippet that is supposed to the expected??

I really don´t know how to handle this.

Translate
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