Hi guys! Seems like I'm forever posting here at the moment!
I'm having a problem where AS seems to be losing data that I've stored in variables when it loops back to the start of a movie clip. I'm not sure why, because I'm not re-declaring the variables everytime at the start, they get defined in a button function.
Basically, what I'm trying to do is set a flag variable, and another called 'continueOnFrame'.
When the movie loops back around, it checks to see if the flag has been set to 1. If it has, then it goes to the frame number contained in 'continueOnFrame'.
Or at least, that's what it SHOULD do. I ran a trace on the variables, and the button function sets them fine, but when the movie lops it sets them to 'undefined' again
And here is the code which actually defines the variables (frame 35 of the movie):
Code:
stop();
news_btn.onRelease = function() {
trace("news_btn pressed");
var flag = 0;
var continueOnFrame = 0;
trace("Flag set to: "+flag+" / continueOnFrame set to: "+continueOnFrame);
gotoAndPlay(36);
};
about_btn.onRelease = function() {
trace("about_btn pressed");
var flag = 1;
var continueOnFrame = 61;
trace("Flag set to: "+flag+" / continueOnFrame set to: "+continueOnFrame);
gotoAndPlay(36);
};
contact_btn.onRelease = function() {
var flag = 1;
var continueOnFrame = gotoAndPlay(36);
trace("success!");
};
I'll attach the .fla file as well if it helps. I'm using MX2004 (although, I've saved the file in MX format).
When you declare a variable as "var flag", that flag is a "local" variable or what we say "temporary" variable. It only exists in this function. It is different from the "flag" outside of this function.
You have "var flag" in news_btn.onRelease function, about_btn.onRelease function and contact_btn.onRelease function. Those "flag"s are all local to that function. They will not affect one another.
If you remove the "var", then the "flag" is a variable outside of the function.