Skip to main content
Known Participant
Oct 27, 2021 8:39 PM UTC
Answered

How To Determine An Instance Name When Adding A Movie Clip From The Library In Animate CC

Hi,

 

I have the following code - 

var fl_MyInstance = new lib.ResetBtns();

 

this.ShowReset.addEventListener("click", fl_MouseClickHandler_2.bind(this));

function fl_MouseClickHandler_2() {

  this.addChild(fl_MyInstance);
  fl_MyInstance.x = 219.05;
  fl_MyInstance.y = 110.55;
} //This code adds a MC from the library and works just fine

 

//This code should call the alert command and does not work

this.ResetButtons.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler() {
  alert("Mouse clicked");
  }

 

The name of the libary item I'm adding is ResetButtons. The Linkage name is ResetBtns. 

 

ResetSVDU is a button within the ResetButtons MC.

 

I've tried ResetButtons, ResetBtns, and fl_MyInstance but I can't get to the ResetSVDU button to trigger the alert command.

 

My question is, what name should I use in the following line?

 

this.????.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));

 

Thanks

    This topic is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Oct 28, 2021 10:18 PM UTC

    Here you go.

     

    https://drive.google.com/file/d/1fV3cwfS9Qqz6cdNHKeiSe7Idz4zaq6Cw/view?usp=drivesdk


    Thanks for the file.

     

    You only need to remove the this keyword from the beginning of line 20.

     

    From this:

    this.fl_MyInstance.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));

     

    To this:

    fl_MyInstance.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));

     

    fl_MyInstance is a variable you created and not a property of the main timeline.

     

    Regards,

    JC

     

    9 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    Oct 27, 2021 10:18 PM UTC

    Hi.

     

    It should be:

    fl_MyInstance.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));
     
    But is ResetSVDU the instance name or the symbol name? Make sure it's the instance name.
     
    Please let us know.
     
    Regards,
    JC
    Translate
    mlb172Author
    Known Participant
    Oct 28, 2021 5:31 PM UTC

    So here's what I'm running. It still doesn't work.

     

    var fl_MyInstance = new lib.ResetBtns();

     

    //set the dynamic text
    this.ShowReset.ResetText.text = "Show Reset Buttons";

     

    this.ShowReset.addEventListener("click", fl_MouseClickHandler_2.bind(this));

    function fl_MouseClickHandler_2() {


    this.addChild(fl_MyInstance);
    fl_MyInstance.x = 219.05;
    fl_MyInstance.y = 110.55;
    }

     

    this.fl_MyInstance.ResetSVDU.addEventListener("click", fl_MouseClickHandler.bind(this));

    function fl_MouseClickHandler() {
    alert("Mouse clicked");

    }

     

    ResetSVDU is the instance name of the button inside the fl_MyInstance MC.

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Oct 28, 2021 6:05 PM UTC

    No problem.

     

    Do you mind sharing the FLA?

    Translate