View Full Version : Problem with _global variable
fxrod77
03-22-2005, 07:53 AM
Hi all:
I've been trying to access a variable within a movieclip on the main timeline and I keep getting undefined.
On frame 1 of the main timeline, I have:
trace(day);
On frame 1 of my circle instance, I have:
_global.day = "Monday"
Shouldn't it trace Monday? This doesn't work for me unless I add another frame and put the trace(day) on frame 2.
I know, this is simple. But any help wiould be greatly appreciated.
Thanks!
-Frankie
Ricod
03-22-2005, 12:14 PM
Sounds to me it's an order problem only. The trace is done before the defining of the day variable. That's why the trace works on the 2nd frame. I think you can find the order of things either in the manual or somewhere here on the forums. What was it ? Bottom layer first, then the frame actions, followed by the objects, then the actions and then the next layer ? To test it, put the circle object on a lower layer, if you want to keep the two (the circle and your frame actions) on the same frame in your timeline.
fxrod77
03-22-2005, 06:17 PM
I have all of my scripts on the top layer, called Scripts.
My circle clip is on the a second layer underneath called Buttons.
As a matter of fact, I'm following the instructions as written in the O'Reilly ActionScript book.
I'm confused as to why it's not working the way it says it's supposed to work. Calling _global variables shouldn't be that hard, huh.
Any other ideas?
Thanks for your time.
-Frankie
Ricod
03-22-2005, 10:57 PM
I know it's the order of things. The trace is called before the frame actions on the 1st frame of your mc is executed and that's why your trace returns "undefined", whereas it works fine when you put your trace on the second frame.
What I don't understand, is why you would call the global variable from the first frame of your main timeline and not after you defined it.
fxrod77
03-23-2005, 12:10 AM
I have a movieclip with a button inside. I want to create a variable that can be accessed on the main timeline when you rollover the button. So, when you rollover the button, a string variable called "where" can be accessed.
Would you mind having a look at my file? I'll post it, if you have the time. :)
Thanks.
Ricod
03-23-2005, 12:20 AM
I understand that, but what I don't understand is why you won't allow for an extra frame on the main timeline.
Also, what you're describing now is the other way around. You define a variable somewhere and then call it from a button. Just make sure you define the variable before you call it.
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.