I'm new to actionscript so please help me if you can.

I've got a main time line with a movie clip called "main" on it. On "main" I have several buttons and each need to set a variable called "destination" to a different value. Then in "main" I aso have another movie clip called "leavinghome".

I've set a variable called "location" on the first frame of "main" and set it equal to 0. This one works perfectly with the code below so when you press the first button, it goes to the frame called "leavinghome".

At the end of the "leavinghome" movieclip timeline, I want the last frame to direct you to a frame called "atRC" back on the timeline of "main".


Here's my code for the first button on "main":

on (release) {
var destination = 1;
if (location == 0) {
gotoAndPlay("leavinghome");
}
if (location == 1) {
gotoAndPlay ("leavingrc");
}
if (location == 2) {
gotoAndPlay ("leavingcontactus");
}
if (location == 3) {
gotoAndPlay ("leavingstudentgrowth");
}
if (location == 4) {
gotoAndPlay ("leavinggallery");
}
if (location == 5) {
gotoAndPlay ("leavingevents");
}

}

and here's my code for the last frame of "leavinghome":

if (destination == 1){
_root.main.gotoAndStop ("atRC");
}


It's playing the "leavinghome" moveclip, but then just repeating it instead of going to the previous level and playing the frame "atRC".
If I take out the "if destination == 1" part, it will work right, but I need it to only work if the variable destination equals 1.

Any ideas?