Skip to main content
Participant
December 7, 2021
Answered

Animate HTML Canvas addChild button problem

  • December 7, 2021
  • 1 reply
  • 614 views

Hi all,

 

when I am adding a Button element from the library using addChild, the button loops throught its four stages continuously (and doesn't function like a button at all).

 

Am I doing something wrong?

 

Many thanks!

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi JC,

    Thanks! It works now. 

    But "funny", every solution brings on a new problem.

    When I use this ButtonHelper,  button.cursor = "pointer" doesn't work anymore.

    I found a work-around by dragging another button instance from the library onto the stage and place it out of sight. Then the pointer on the dynamically added button works also again.

    What is the cause and what is the "clean" solotion for this?

     

    Cheers,

    Peter


    Hi again, Peter!

     

    The ButtonHelper class actually set the cursor property to "pointer" automatically. But it was my fault to not mention that the stage.enableMouseOver() method has to be called first so that mouse over interactions work.

     

    The reason is that when we create a regular Button symbol in Animate, the stage.enableMouseOver call is added automatically in the publishing process. But if there's no Button symbol instance on stage, we have to call it manually ourselves.

     

    I've just edited my second answer including the stage.enableMouseOver call.

     

    I hope it helps.

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 7, 2021

    Hi.

     

    It's because the Button symbol by itself in the Library is just a MovieClip.

     

    What Animate does in the publishing process is to wrap the symbol instances we add/create in the IDE in ButtonHelper instances so that the MovieClip symbol acts like an AS3 Button.

     

    You can check it for yourself in the published code:

     

    So for buttons added at the runtime from the Library, we have to manually call the stop method on them.

     

    I hope this helps.

     

    Regards,

    JC

    Participant
    December 7, 2021

    Many, many thanks!

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 7, 2021

    You're welcome!

     

    I forgot to say that if you want to keep the Button behavior, you're gonna have to create an instance from the ButtonHelper class yourself and not just call the stop method.