Skip to main content
Participant
May 11, 2023
Answered

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

  • May 11, 2023
  • 1 reply
  • 438 views

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 has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 11, 2023

    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

    Participant
    May 11, 2023

    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

    kglad
    Community Expert
    Community Expert
    May 12, 2023

    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)