Skip to main content
Sharpe D
Known Participant
December 15, 2021
Answered

call function from button and inside function

  • December 15, 2021
  • 1 reply
  • 220 views

 

I have a function updateScreen to update text fields. I want to call the function from inside another buttons function.

 

function updateScreen() {

            (updates numerous text fields)

};

 

btnOne.addEventListener("click",  updateOne.bind(this));

function updateOne() {

           (changes variables);

           updateScreen()

}

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    If your code lives in different instances, one approach would be to make the updateScreen function a method of the main timeline. Like this:

     

    // CODE IN THE MAIN TIMELINE
    this.updateScreen = function()
    {
    	// (updates numerous text fields)
    };
    
    
    // CODE SOMEWHERE ELSE
    btnOne.addEventListener("click", updateOne.bind(this));
    
    function updateOne()
    {
    	// (changes variables);
    	// exportRoot is a global variable automatically created in the
    	// publishing process that stores a reference to the main timeline
    	exportRoot.updateScreen();
    }

     

     

    I hope this helps.

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    December 15, 2021

    Hi.

     

    If your code lives in different instances, one approach would be to make the updateScreen function a method of the main timeline. Like this:

     

    // CODE IN THE MAIN TIMELINE
    this.updateScreen = function()
    {
    	// (updates numerous text fields)
    };
    
    
    // CODE SOMEWHERE ELSE
    btnOne.addEventListener("click", updateOne.bind(this));
    
    function updateOne()
    {
    	// (changes variables);
    	// exportRoot is a global variable automatically created in the
    	// publishing process that stores a reference to the main timeline
    	exportRoot.updateScreen();
    }

     

     

    I hope this helps.

     

    Regards,

    JC