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

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

Explorer ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

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.

Views

150

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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