Skip to main content
Participant
May 11, 2023 4:24 PM UTC
Answered

Transfer variables from one frame to another using HTML 5 Canvas in Animate CC?

Hi,

 

 How to transfer variables from one frame to another frame in the timeline? Example: 

 

Frame 1: I created the user input text boxes. User will fill up their details into the input text boxes.

 

Frame 5: I wish to retrieve the user input data (username, etc) in Frame 1. in a dynamic text.

 

Hope can hear valuable comments from experts. Thanks

 

Regards

Charlie

 

 

    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
    May 11, 2023 5:53 PM UTC

    Hi.

     

    Store the values that you want as properties of the main timeline instead of variables.

     

    For example:

    // frame 0 of the main timeline
    this.userName = "John";
    
    // frame 1 of the main timeline
    this.yourTextField.text = this.userName;

     

    I hope this helps.

     

    Regards,

    JC

    4 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 11, 2023 5:53 PM UTC

    Hi.

     

    Store the values that you want as properties of the main timeline instead of variables.

     

    For example:

    // frame 0 of the main timeline
    this.userName = "John";
    
    // frame 1 of the main timeline
    this.yourTextField.text = this.userName;

     

    I hope this helps.

     

    Regards,

    JC

    Translate
    Participant
    May 11, 2023 11:25 PM UTC

    Thanks JC for your reply

     

    Let's say I insert a user input textbox with the instance name of userinput and a button ("NextBTN") to navigate to next frame. and code for frame 0:

    var _this = this;

    _this.stop();

    this.userName = document.getElementById("userinput").value;

    _this.NextBTN.on('click', function(){

    _this.gotoAndStop(1);
    });

     

    After that, I create dynamic text with the instance name of DTXT and code Frame 1 is:

    this.DTXT.text = this.userName;

     

    Can you help me to point out my mistake? Sorry ya, I am a newbie to coding and just started to learn.

     

    Regards

    Charlie

    Translate
    kglad
    Community Expert
    Community Expert
    May 12, 2023 1:17 AM UTC

    you're assigning the variable before there's text in the input field.  ie, execute that code when the button is pressed (and error check that there's actually text)

    Translate