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

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

Explorer ,
Jan 05, 2022 Jan 05, 2022

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.

169
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 ,
Jan 05, 2022 Jan 05, 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

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
Explorer ,
Jan 09, 2022 Jan 09, 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.

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
Explorer ,
Jan 09, 2022 Jan 09, 2022
LATEST

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.

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