Skip to main content
George Bernard
Inspiring
January 5, 2022
Question

How to add event to button after create tween to it?

  • January 5, 2022
  • 1 reply
  • 222 views

I have set of buttons, normally I would let button stay as it is and call its instance name to add event listener. But this time I tried to make it moving, I created a classic tween to it, then named the classic tween instance name. 

Normally, this is the code:

this.btn_name.on("click", function() {...});

So this time, I just add the tween's instance name before it:

this.tween_name.btn_name.on("click", function() {...});

And it's not working anymore. I can't seem to find the answer in the community. Please help.

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 5, 2022

    Hi.

     

    You can just add the event listener to the button like you would normally do without worrying about the tween.

     

    Or is there something else going on?

     

    Regards,

    JC

    George Bernard
    Inspiring
    January 10, 2022

    No, it's not working. I have tried to put the code inside the tween but still not working.

    Here is the page, could you please check it.

    https://xenodochial-brahmagupta-9e2db9.netlify.app/

    In "Projects" section, I use buttons for my work and I want to redirect the web when click on it.

    George Bernard
    Inspiring
    January 10, 2022

    What I have tried:

    - Named the tween and put the code in root. (root.tween_name.button_name.onclick)

    - Skip the tween name, code still in root. (root.button_name.onclick)

    - Put the code inside tween (this.button_name.onclick)

    It's work if I don't have tween on buttons layer but that's not what I want.