0

I need help with JavaScript in Adobe AnimateCC:

I have two different movie clips and a button. I would like to be able to click on a movie clip (making it the currentTarget) and then click on a button which calls the currentTarget (the just-clicked-on movie clip) and makes it do something -- move 500 px along x for example. Here's my code so far. Any help will be greatly appreciated.

this.grayPentagon_1_mc.addEventListener("click", clickSomePentagon.bind(this));
this.grayPentagon_2_mc.addEventListener("click", clickSomePentagon.bind(this));

function clickSomePentagon(e)
{
    alert(e.currentTarget);
    var myPentagon = e.currentTarget;
}

this.red_btn_1.addEventListener("click", makeSomePentagonMove.bind(this));

function makeSomePentagonMove()
{
    alert("move my pentagon");
    myPentagon.x = 500; 
}
Zaffer
  • 17
  • 2

1 Answers1

0

My bad, I apologize. I should have declared the variable var myPentagon outside the function clickSomePentagon, then referenced the declared variable in the function, like this, which works.

var myPentagon;

this.grayPentagon_1_mc.addEventListener("click", clickSomePentagon);
this.grayPentagon_2_mc.addEventListener("click", clickSomePentagon);

function clickSomePentagon(e)
{
    //alert(e.currentTarget);
    myPentagon = e.currentTarget;
}

this.red_btn_1.addEventListener("click", makeSomePentagonMove.bind(this));

function makeSomePentagonMove()
{
    //alert("move my pentagon");
    myPentagon.x = 500; 
}
Zaffer
  • 17
  • 2