Skip to main content
Inspiring
May 18, 2016
Answered

click events in Adobe Animate CC

  • May 18, 2016
  • 2 replies
  • 10369 views

Dear Friends,

Iam converting an elearning lessons from Flash AS3 to  Animate CC - JS. I have the following code for an activity like click each buttons and see corresponding popups.

import flash.events.MouseEvent;

for (var i:Number = 1; i<=5; i++)

{

this["btn" + i].addEventListener(MouseEvent.CLICK, btn_clicked);

}

function btn_clicked(event:MouseEvent)

{

trace(event.target.name.substr(3));

popup.gotoAndPlay("pg"+event.target.name.substr(3));

}

it should go to particular popup.

Kindly help me to convert this to java script code in animate CC.

Thanks in Advance,

Syed Abdul Rahim

This topic has been closed for replies.
Correct answer rahimhaji

Thks Mr.kgla,

I did this in the following way:

this.stop();
var sel_but = "";
_this = this;
for (inc1 = 1; inc1 <= 7; inc1++) {
this["btn_" + inc1].name = "button" + inc1;
this["btn_" + inc1].addEventListener("click", fl_MouseClickHandler);
}

function fl_MouseClickHandler(event) {
sel_but = event.target.name.substr(6);
_this.popUp.gotoAndPlay('pg'+sel_but);
}

May be useful to others...

2 replies

rahimhajiAuthorCorrect answer
Inspiring
May 22, 2016

Thks Mr.kgla,

I did this in the following way:

this.stop();
var sel_but = "";
_this = this;
for (inc1 = 1; inc1 <= 7; inc1++) {
this["btn_" + inc1].name = "button" + inc1;
this["btn_" + inc1].addEventListener("click", fl_MouseClickHandler);
}

function fl_MouseClickHandler(event) {
sel_but = event.target.name.substr(6);
_this.popUp.gotoAndPlay('pg'+sel_but);
}

May be useful to others...

kglad
Community Expert
Community Expert
May 22, 2016

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

kglad
Community Expert
Community Expert
May 18, 2016

:

var tl=this

for (var i = 1; i<=5; i++)

{

this["btn" + i].addEventListener('click', btn_clicked);

this["btn"+i].name=i.toString();

}

function btn_clicked(event)

{

tl.popup.gotoAndPlay("pg"+event.currentTarget.name);

}