# Global var using in Flash MX

**URL:** https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004
**Category:** Uncategorized
**Created:** [December 2, 2002, 9:36pm UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004 "2002-12-02T21:36:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![olegkot](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@olegkot](https://forum.kirupa.com/u/olegkot)
#### Post date: [December 2, 2002, 9:36pm UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004/1 "2002-12-02T21:36:04Z")

</div>

Hi!

I’m trying to set global var at the main movie timeline in first frame. Than I need to reach and to change this var inside of the sub-mc every time when it plays in loop with main mc.

In details: there is a sub-sub-mc which gets visibility from sub-mc depending on this global var, and also changes this global var. So I need to reach it and change every loop of mc.

Would be very glad to get any suggestions. I tryed many ways - nothing has worked.

oleg. ☹

---

<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 2, 2002, 9:40pm UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004/2 "2002-12-02T21:40:07Z")

</div>

refer to your variable as \_root.variablename that will target a variable located on the main timeline.

---

<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 3, 2002, 9:55am UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004/3 "2002-12-03T09:55:40Z")

</div>

Thx!

But how to declare the var?

var a = 0;  
\_global.a = 0;

and where?

oleg.

---

<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 3, 2002, 2:19pm UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004/4 "2002-12-03T14:19:46Z")

</div>

\_root.a = 0;

this would be for a variable named a at the root timeline which is global.

---

<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 3, 2002, 4:27pm UTC](https://forum.kirupa.com/t/global-var-using-in-flash-mx/9004/5 "2002-12-03T16:27:20Z")

</div>

At least concearning the flash 5 version(don´t now if it changed in FMX):

Global variables are variables that can be set or retrieved at any point anywere. What you are sugesting is just a variable located a the root, then, a _ **local** _ variable located at the root (or main timeline) not global.  
Global variables don´t exist on flash they are simulated by this code:

```php
Object.prototype.yourGlobalVariable = value;

```

But it is easier if you refer to a variable to the respective location .

**Example:** You want to set the value of the **pamelaAndersonIsHot** variable located inside the movieclip **foxy** at the main timeline (\_root) to **true** :

```php
_root.foxy.pamelaAndersonIsHot = true;

```

😛

=)
