Global Variables not working ? ..help

I declared my global variable with _global.MyBackGround = “Main”
i did a trace(_global.MyBackGround) and it is still “Main” , but i can’t get the swapdepths to work …

main.swapDepths(_global.MyBackGround);

but if i do this:

main.swapDepths(Web); … it works…my Main MC swapsdepth with the Web MC …

i have 5 layers with 5 separate movie clips on them, i just wanna swap my “Main” with another 1 of those 4 which i have instanced-named them … eg…one of them is Web.

any ideas ? … really need this variable passing to work so i can switch my backgrounds on the fly… please help …

Thanks…

Hi,

Just use a depth stack number(i.e. 10) as your “displaying” depth.
U can swap depths with a number (that number being the z stacking order{0 the ‘deepest’}).


main.swapDepths(10);
//...later...
web.swapDepths(10);
//...and back...
main.swapDepths(10);

Hope it helps

Cheers

SHO

has anyone tried this …

_global.MyMovie = “web”

_global.MyMovie.swapDepths(10);

why can’t this work ?:*(

I have dealt with this issue and I work with other programming languages and I feel your pain. When we talk about variables we mention scope, local and lifetime and of course global.
Global is supposed to be “universal” but for flash it seems to have limitations.

I was told by an expert that as long as you use _global its global, I don’t know. depends on what your definition of ‘it’ is I guess…

Hi,

I don’t think this is a problem of variable scopes… _global is allways global!

Your problem here is that you’re trying to swap the depth of a string!
I take it that you want to swap the depth of a MC, isn’t it?
in your example:

_global.MyMovie = “web”

_global.MyMovie.swapDepths(10);

MyMovie being global can be accessed from anywhere so doesn’t need the ‘_global’ bit anymore

MyMovie = “web” // MyMovie equals the string web not a MC

Assuming you’ve got a MC with an instance, on the same timeline as the code, named web your code should be:


_global.MyMovie = web;//web in this case is an object (a MC);

MyMovie.swapDepths(10);

or


_global.MyMovie = eval("web");//evaluate 'web' string an return an object with the same name if there's one
MyMovie.swapDepths(10);

And to tell you the truth I don’t think you need to make MyMovie a global variable at all.

Hope it helps

Cheers

SHO

Actionscript is not a case sensitive language (it’s case INsensitive). “Main” is getting mixed up with “main” and you are swapping a movie clip with itself.

If you do something like you tried, it won’t work:

_global.MyBackGround = “Main”
main.swapDepths(_global.MyBackGround);

so, your main.swapDepths(“web”) would work because you are swapping a clip with a different clip, not a clip with itself.