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

Several buttons in a frame (html5 canvas)

New Here ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

Hi !

I am a beginner in Animate I would like to have several buttons (with different target in a frame on my animation (HTML5 canvas), but I can only operate one.
I put the following code on my "Actions" timeline :
"This.stop ();
this.buttonname1_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame.bind (this));
function fl_ClickToGoToAndPlayFromFrame ()
{this.gotoAndPlay ( "target1");} "

 

this.buttonname2_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame.bind (this));
function fl_ClickToGoToAndPlayFromFrame ()
{this.gotoAndPlay ( "target2");} ".

 

this.buttonname3_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame.bind (this));
function fl_ClickToGoToAndPlayFromFrame ()
{this.gotoAndPlay ( "target3");} ".

 

The first button works well, but not the others 😕

So, my question : what is the right code for having several buttons ?

Thanks a lot !

 

JLS

TOPICS
Code , Timeline

Views

236

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
LEGEND ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

You gave each click handler function the exact same name. How do you think it's supposed to tell which is which if you do that?

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
Engaged ,
Nov 29, 2019 Nov 29, 2019

Copy link to clipboard

Copied

LATEST

As Clay mentioned you have given each function the same name. You need to have each function named differently.

 

Try this (I have bolded and turned text to red to show what I added)...

 

this.stop ();
this.buttonname1_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame1.bind (this));
function fl_ClickToGoToAndPlayFromFrame1 ()
{this.gotoAndPlay("target1");} 

 

this.buttonname2_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame2.bind (this));
function fl_ClickToGoToAndPlayFromFrame2 ()
{this.gotoAndPlay("target2");} 

 

this.buttonname3_btn.addEventListener ("click", fl_ClickToGoToAndPlayFromFrame3.bind (this));
function fl_ClickToGoToAndPlayFromFrame3 ()
{this.gotoAndPlay("target3");}

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