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
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?
Copy link to clipboard
Copied
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");}