Pass a user name to another frame - how do you do it? AS3

Onframe1 , I created a global variable for the user name as follows:

var userNameGlobal:String = certificateName.text;

On frame 2, I created a dynamic text field and tried to concatenate the user name with other string information and the user name entered by the user in frame 1 does not display in the dynamic text field.

information.text == "Hello, " + userNameGlobal + " how are you doing today?";

What am I doing wrong? Thanks for any help you can provide.

you want = not == :wink:

I changed it to = and for some reason the userNameGlobal information typed by the user is not displaying in information.text.

Here’s what I have now.

Frame 1
var userNameGlobal:String certificateName.text;

Frame 2

information.text = “Hello, " + userNameGlobal + " how are you doing today?”

It displays as follows: Hello, how are you doing today?

I performed a trace on frame 2 and nothing displayed on the Output window, so it is not recognizing the global variable name on frame 2.

frame one still needs the = too. Did you remove that?

Edit:

Also, if certificateName is an input field, and not something that already has a value in it, if you just have the userNameGlobal in the frame script on frame one, it will be assigned the initial, empty value of the textfield. Not anything anyone puts in there before the timeline progresses.

Sorry, I forgot to put the = sign in there

frame 1 shows:

var userNameGlobal:String = certificateName.text;

yes, certificateName.text is an input text field with no value in it.

Then “Hello, how are you doing today?” is the expected output. If you want it to have the name, you need to set userNameGlobal when you leave that frame. Still declare it with var in the frame script (to make it “global”), but also set it to the current value of certificateName.text when you move away from that view.

the problem is in frame 1 because when I ran a trace on frame1 nothing displayed in the output window.

like this:

Frame 1

var userNameGlobal:String = certificateName.text;

navigation_btn.addEventListener(MouseEvent.CLICK, goNext);
function goNext(e:MousEvent):void
{
   gotoAndPlay("2");
   userNameGlobal = certificateName.text
}

the script actually has e:MouseEvent in it, not e:MousEven

Right, because that first line only gets called at the very start of the frame and never again unless you leave that frame and come back. So it will immediately assign userNameGlobal to an empty string (the initial value of certificateName.text) and leave it that way because it captures the value of certificateName.text at that point in time and doesn’t get updated until you do the assignment again.

By having it in the goNext function, you’re making sure userNameGlobal has the most recent value of certificateName.text when you leave that frame, which should have whatever value any user put in there up until clicking on the navigation_btn button.

Its important that you didn’t only have var userNameGlobal:String = certificateName.text; in the goNext function because using var there would mean that the variable userNameGlobal would be defined just for that function and not for the whole timeline as is the case when you declare it in the main frame script body. If only in the function, other frames couldn’t reference it. In fact other script in that same frame couldn’t reference it unless in that same goNext function because vars in functions are only in those functions.