# \_global isn't global

**URL:** https://forum.kirupa.com/t/-global-isnt-global/6724
**Category:** flash
**Created:** [October 15, 2002, 1:57am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724 "2002-10-15T01:57:31Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![anil](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anil](https://forum.kirupa.com/u/anil)
#### Post date: [October 15, 2002, 1:57am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/1 "2002-10-15T01:57:31Z")

</div>

Can anyone tell me if I have to use \_root instead of \_global?  
I am loading a movie into an empty movie clip,  
but when it is loaded it seems to have it’s own \_global object!

Like maybe all the core objects are the same,  
but anything I put in there isn’t.  
The loaded movie sees objects it has created in \_global,  
but not the objects that were already created in \_global  
before it was loaded.  
And vice-versa for the \_root movie.

Anil

Here is some code from the movie that is loaded:  
\_global.hello=“hello”;  
\_global.another=“whatdyanow”;  
for(one in \_global){  
this.status+="  
"+one;  
}  
It displays ‘hello’ and ‘another’ in the ‘status’ textfield.  
But nothing else.

Here is some code from the existing \_root movie:  
for(one in \_global){  
Y.Log(one);  
}  
The Y.Log code displays all the properties and sub-objects  
(including the Y object which it is a sub-object of, in \_global)  
that are placed in \_global by the \_root movie,  
but not “hello” and “another”.

---

<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: [October 15, 2002, 2:27am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/2 "2002-10-15T02:27:23Z")

</div>

Just use \_root, unless you really need the scope of the variable to be available in all areas of your movie. As it is, all objects in Flash MX have \_global properties, that is why you see them as such. It is much simpler to simply use your variables with \_root. That should simplify matters.

---

<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: [October 15, 2002, 2:43am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/3 "2002-10-15T02:43:01Z")

</div>

Wow! That is the quickest reply!  
Thanks for your help IAmMontoya…

Actually, yes, I did rather want the object to be totally global.  
That’s why I used \_global!  
It is crucial that it is global, I have to find a way round this.

I guess using \_root will work,  
I am about to try it out right now.  
But I find \_global simpler (when it works),  
because the target path is cleaner.  
I like shorter identifiers,  
especially when the code gets complex,  
which it will.

I guess I’d just like to know whether \_global is actually global,  
if I’m just using it in the wrong way…  
Or whether when Macromedia say \_global is global they are lieing.

At least then I can happily go on my way to make a kludge,  
without thinking I am missing out on it being better.

Thanks for your time and consideration.  
Anil

---

<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: [October 15, 2002, 3:18am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/4 "2002-10-15T03:18:35Z")

</div>

\_global is global… which really means that once you do

\_global.myvar=100;

you can reference myvar by itself, and it should recognize it anywhere in any movie clip. You do not have to use \_global.myvar to reference it again.

---

<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: [October 15, 2002, 4:09am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/5 "2002-10-15T04:09:29Z")

</div>

Now it’s really getting tough.

Yes, \_global SHOULD be \_global.  
I SHOULD be able to access any \_global subobject,  
without using any target path.  
I can do this:  
\_global.Y = {};  
Y.Log=function(msg){somecode=inhere;};  
And then access the Log function anywhere,  
just by using:  
Y.Log(“Log this message”);

And it does work,  
but only inside the main (’\_root’) movie.

When I download another movie like this:  
var mc;  
\_root.createEmptyMovieClip(Q.q[2],Q.depth);  
mc=\_root[Q.q[2]];  
mc.\_visible=true;  
mc.\_x=Q.q[4];  
mc.\_y=Q.q[5];  
mc.loadMovie(Q.liburl+Q.q[3]);  
The new movie CAN’T SEE the \_global environment.  
ALSO I just discovered, it CAN’T SEE the \_root environment!  
It actually has a totally empty \_global and \_root.

In fact, even though a targetPath(this) statement  
inside the downloaded movie returns ‘\_level0.menu’  
(Q.q[2] = ‘menu’)  
A 'for(varname in \_level0){} statement doesn’t find ANYTHING.

To make it worse, using the debugger DOES reveal  
ALL the \_global objects for BOTH movies, side by side,  
just the way they SHOULD be.

Aaaaaarrrrrrrgggggghhhhhh!!!  
Anil

---

<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: [October 15, 2002, 11:23am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/6 "2002-10-15T11:23:48Z")

</div>

functions are different and can only be called by addressing them properly.

---

<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: [October 15, 2002, 2:58pm UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/7 "2002-10-15T14:58:44Z")

</div>

Woo that’s strange. I’ll test this… when my computer starts functionning normally.

---

<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: [October 15, 2002, 3:22pm UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/8 "2002-10-15T15:22:45Z")

</div>

I made a very simple test, it works for me. You must be doing something wrong… but what :q:

pom :cyclops:

---

<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: [October 16, 2002, 4:25am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/9 "2002-10-16T04:25:01Z")

</div>

ilyaslamasse/pom

i am so glad to here that this works for you!  
i need it to work for me too!

could you post your test fla for me please?

i am about to back out on the flas that i have got  
and start all over again with a very simple test fla  
that only tackles this problem and nothing else  
then i can double prove it

but if you can send me your fla  
then things could be happening for me a whole lot quicker

thanks for your post  
anil

---

<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: [October 16, 2002, 5:35am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/10 "2002-10-16T05:35:31Z")

</div>

now i have created two VERY simple flas and they work  
they do everything they are supposed to do  
none of the problems that i had before are present!

thankyou Lord JESUS !

now i guess i only have to work out the differences  
between these ones and what i had before

if i come up with anything interesting i will post here

thanks for all your help and encouragement

anil

---

<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: [October 18, 2002, 4:01am UTC](https://forum.kirupa.com/t/-global-isnt-global/6724/11 "2002-10-18T04:01:29Z")

</div>

well well very strange  
seems like i have found some ‘undocumented behaviour’  
how’s this:  
the following \_global is visible using for (i in \_global) {}:  
\_global.Q = “hello my name is Q”;  
but this one just doesn’t appear at all using the same code:  
\_global.O = “hello my name is the big letter O”;  
so maybe macromedia have secretly reserved \_global identifiers whose name begins with ‘O’?

i have brought my new code up to do exactly what it did before,  
i went step by step only adding code to the simple fla  
that i knew already worked, and testing it every time

so now i have two fla’s  
they both do the same thing  
but only one of them works  
while the other one has all the problems mentioned before

i wouldn’t believe it myself if i didn’t run the swfs 100 times each  
and watch the same thing happen over and over again

at least my problem is fixed

thankyou everyone  
thankyou jesus

anil
