# \_global assignment

**URL:** <https://forum.kirupa.com/t/-global-assignment/38517>\
**Category:** flash\
**Created:** [December 24, 2003, 6:18am UTC](https://forum.kirupa.com/t/-global-assignment/38517 "2003-12-24T06:18:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![riveroaks](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@riveroaks](https://forum.kirupa.com/u/riveroaks)\
**Post date:** [December 24, 2003, 6:18am UTC](https://forum.kirupa.com/t/-global-assignment/38517/1 "2003-12-24T06:18:55Z")

</div>

Im trying to use global variables right now for fields of different things in my game. I declare one global variable on the first frame of my movie and then assign that name to a text box for the user’s name. Then on the next frame I have a movieclip with a dynamic text box in it which is of the same variable name, yet that text box won’t display the user name. I did a trace within this movie clip and the variable im using returns nothing. Why might this be? Are there any common mistakes when it comes to global variables.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 9:46am UTC](https://forum.kirupa.com/t/-global-assignment/38517/2 "2003-12-24T09:46:09Z")

</div>

> \*Originally posted by riveroaks \*  
> \*\*I declare one global variable on the first frame of my movie and then assign that name to a text box for the user’s name. \*\*  
> What do you mean by that? That you name your textbox after the global variable?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 4:43pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/3 "2003-12-24T16:43:34Z")

</div>

it means that in the actions panel i declare something like this:

```auto

_global.myVariable = "";

```

and then i enter “myVariable” into the variable slot in the textbox’s properties

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 5:22pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/4 "2003-12-24T17:22:49Z")

</div>

I don’t think it’s a good idea. You should separate them

```auto
_global.myVar = "pomegranate is wonderful";

myTF.text = _global.myVar;

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 5:44pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/5 "2003-12-24T17:44:03Z")

</div>

ok that brings up one more question…when i change a global variable do i need to reference it as \_global.myVar = whatever or do i just say myVar = whatever?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 9:09pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/6 "2003-12-24T21:09:13Z")

</div>

when declareing it you use

```auto

 _global.myVar = "whatever";

```

after that just use

```auto

myVar = "whatever";

```

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 24, 2003, 9:55pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/7 "2003-12-24T21:55:35Z")

</div>

My advice would be to use \_globals sparingly. The previous post should say it all ^. Once you start getting global happy, you’re bound to overwrite a local variable with a global or vice versa. The only time i would see fit to use globals is when your movie contains multiple scences, but that’s JMO. I just got really acustomed to using relative paths. Even absoulte paths are better than globals… sometimes.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 25, 2003, 7:16pm UTC](https://forum.kirupa.com/t/-global-assignment/38517/8 "2003-12-25T19:16:22Z")

</div>

Norie’s right 🙂 [http://www.kirupa.com/developer/actionscript/tricks/global.htm](http://www.kirupa.com/developer/actionscript/tricks/global.htm)
