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.
*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?
it means that in the actions panel i declare something like this:
_global.myVariable = "";
and then i enter “myVariable” into the variable slot in the textbox’s properties
I don’t think it’s a good idea. You should separate them
_global.myVar = "pomegranate is wonderful";
myTF.text = _global.myVar;
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?
when declareing it you use
_global.myVar = "whatever";
after that just use
myVar = "whatever";
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.