Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : how to make global variables


freak_oz
9/11/2004 7:11:05 PM
i got an variable gun in my "game" and that's assinged in the normal movie but when i do in an movie clip if gun eq "true" then it cant find the variable why and how to fix?
abeall
9/11/2004 7:23:51 PM
add _root

freak_oz
9/11/2004 7:34:33 PM
abeall
9/11/2004 8:18:01 PM
I'm assuming when you ramble:
[quoted text, click to view]

You mean:
I am working on a game, and I have a variable created on the main movie
timeline called "gun". [no explaination of what this vairable contains]

And when rambling on:
[quoted text, click to view]
variable

You mean:
When I try to access this variable to see if it equals "true", it says
"undefined".

So the problem is you have created a var 'gun' on the main timeline but can't
figure out how to access it from another timeline(MovieClip). This would follow
your deceivingly coherent subject: "how to make global variables". This is also
the age old problem of scoping: you need to learn how to reference things.

SOLUTION
Assuming my translation is correct, you need to add "_root." before attempting
to access the variable. Example:

_root.gun

if(_root.gun==true){};
BTW, the above is also the same as
if(_root.gun){};

HTH
abeall
9/11/2004 8:48:32 PM
another option, which i wouldnt normally suggest, but you seem near hopeless:
use the _global method. In other words, where "gun" is first defined, do it
like this:

_global.gun=false;

now you can just refer to it as "gun" from anwhere
AddThis Social Bookmark Button