This content has been marked as final.
Show 5 replies
-
1. Re: Global Variable Not Working?
kglad Oct 13, 2008 10:57 AM (in response to convrgr)use double equal (==) to test for equality. -
2. Re: Global Variable Not Working?
convrgr Oct 13, 2008 11:58 AM (in response to convrgr)Opps, fixed that but still it only loads the aspen page everytime... I dunno. -
3. Re: Global Variable Not Working?
Rothrock Oct 14, 2008 7:50 AM (in response to convrgr)That is because that is what you are telling flash to do. Remember it does what we tell it, not what we want.
Okay, near the top you set both austinVar and atlantaVar, so they each have a value.
Then when you get to the script after the tween you have an
if(){}if else(){}else{}
Structure. So since you have clearly set austinVar to 1, what does the first part of that conditional do? It says true. Well once a conditional tree like this starts evaluating and finds a true it doesn't do any more of the tree. Why would it? Because you can't be "else" if you are already something true.
My guess is that you don't want to have an austinVar and atlantaVar (which are kinda bad names for variables anyways). My guess is that you want something like:
var theCities:Array=["Austin","Atlanta","Philly"];
var currentCity:Number=0
And then you could do things like:
stop();
gotoAndPlay(theCities[currentCity]+"IN");
or like this:
var selectedCity:MovieClip=this["city"+theCities[currentCity]]
selectedCity.cityfade.city.text = theCities[currentCity].toUpperCase();
selectedCity.onRollOver = over;
selectedCity.onRollOut = out;
selectedCity.onRelease = function() {
_global.currentCity = 2;
_root.gotoAndPlay("start"+currentCity+"OUT");
}; -
4. Global Variable Not Working?
convrgr Oct 15, 2008 6:16 AM (in response to Rothrock)My code is on a seperate .as file, so wouldn't it have to be a global variable? Am I supposed to call that .as at the frame label I make the code trigger to? "aspenIN" and "atlantaIN" are frame labels, so i don't think
gotoAndPlay(theCities[currentCity]+"IN");
will work. It's gotta call the frame label somehow. -
5. Re: Global Variable Not Working?
Rothrock Oct 15, 2008 7:44 AM (in response to convrgr)theCities is an array of cities and currentCity is a number representing which element (starting from zero) in that array to pick. So when currentCity is one it will find that the array holds a string called Atlanta and smash it together with "IN" and then it will go to that label. You are correct in that AtlantaIN and atlantaIN aren't the same and that is a silly mistake I just made, but I think you can see how to fix that... :)
As for _global, they really are not something that is needed. It is just a quick fix for not well designed scope structure. I don't use it very often and in AS3 the _global object has been removed.
Without knowing all the ins-and-outs of your specific project it is hard to advise you on exactly what to do. But if _global works for you in this project and you don't have the time or desire to mess it all up by trying something new...well then don't!
One thing that is certain is that if austinVar is equal to 1 then the code you gave will never get past the first if statement.