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
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
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
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
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)
Copy link to clipboard
Copied
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.