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

**URL:** <https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270>\
**Category:** flash\
**Created:** [March 6, 2015, 3:18pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270 "2015-03-06T15:18:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 3:18pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/1 "2015-03-06T15:18:12Z")

</div>

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

```auto
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.

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

```

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

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 6, 2015, 3:41pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/3 "2015-03-06T15:41:58Z")

</div>

you want = not == 😉

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 3:50pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/4 "2015-03-06T15:50:16Z")

</div>

> [@rhanna2](#):
>
> var userNameGlobal:String = certificateName.text;

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

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 3:54pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/5 "2015-03-06T15:54:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 3:57pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/6 "2015-03-06T15:57:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 6, 2015, 4:06pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/7 "2015-03-06T16:06:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 4:16pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/8 "2015-03-06T16:16:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 6, 2015, 4:19pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/9 "2015-03-06T16:19:40Z")

</div>

> [@rhanna2](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 4:19pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/10 "2015-03-06T16:19:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 4:24pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/11 "2015-03-06T16:24:05Z")

</div>

like this:

Frame 1

```auto
var userNameGlobal:String = certificateName.text;

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

```

---

<div class="post-metadata">

**Author:** ![rhanna2](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@rhanna2](https://forum.kirupa.com/u/rhanna2)\
**Post date:** [March 6, 2015, 4:26pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/12 "2015-03-06T16:26:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 6, 2015, 4:32pm UTC](https://forum.kirupa.com/t/pass-a-user-name-to-another-frame-how-do-you-do-it-as3/569270/13 "2015-03-06T16:32:03Z")

</div>

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.
