• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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

 

 

Views

362

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 11, 2023 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

Votes

Translate

Translate
Community Expert ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

LATEST

It's just like @kglad said. You have to get the user input in the click handler function. Like this:

 

var _this = this;

_this.stop();

_this.NextBTN.on("click", function()
{
    _this.userName = document.getElementById("userinput").value;
    _this.gotoAndStop(1);
});

 

But also keep in mind that the Animate publishing process sometimes fails to register text fields in frames bigger than 0. So I advise you to place the text field instance inside of a Movie Clip instance if you get invalid references.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines