Random Background question

Hi,

I load a Random Background (for Home) in my movie, all works perfect. My question is:

Wenn I go back to Home (home button), I want to display the same Background that Flash loaded first.

Is there a way to do that?, to assign a variable to the movie that Flash loads?

I used this code to load the random movie:

choice = Math.round(Math.random()*5);
switch (choice) {
case 0 :
myemptymovie.loadMovie(“image0.swf”);
break;
case 1 :
myemptymovie.loadMovie(“image1.swf”);
break;
case 2 :
myemptymovie.loadMovie(“image2.swf”);
break;

And for the home button I use the same code but with:

on (release) {
choice = Math.round(Math.random()*5); …

Thanks for your help…

could be done in more than one way…

1 way to do it is to set a root variable in each of your backgrounds for example in the first frame of each background put a variable:

in background 1 put =


_root.mybackground =1;

in background 2 put =


_root.mybackground =2;

and so on.

Then on your button you could use another switch, command or a series of IF commands, either will work and have the same effect:


on (release) {
if (_root.mybackground ==1) { myemptymovie.loadmovie("image0.swf");
}
if (_root.mybackground ==2) { myemptymovie.loadmovie("image1.swf");
}
}

any problems post back.

it works perfect, THANKS :thumb:

But I have a new question, Can I <b>assign a variable to a Label</b> from a Movie, in order to for exaple:

Tell Flash to play “STEP3” from MOVIE_A when the MOVIE_B stops in label “STEP1”.

A kind of intelligent button, I can post a movie with a explanation of what I really mean.

Thanks once again!

Hi, no problem :slight_smile:

I would certainly think thats possible, and you could do it in a similar way.

Just use an if statement to test whats going on. I never label anything so I am not great on how they work! I usually plan things on paper and write in english what I want it to do then code it if its complicated… fairly basic way of doing things but it helps to prevent errors.

I will do it with frame numbers cause I know it will work:

For examples sake lets say “Step 1” in movie_B is frame 100, and lets say “Step 3” in movie_A is frame 300.

Then attach to the button:


on (release) {
       If (movie_b._currentframe>=100) {
            movie_a.gotoAndPlay(300);
        }
}

I think to do that with labels it would be:


on (release) {
       If (movie_b._currentframe="STEP1") {
            movie_a.gotoAndPlay("STEP3");
        }
}

alternatively you could use another variable, in the first frame of STEP1 you could put :


_root.stepvar=1;

then on the button put:


on (release) {
       If (_root.stepvar==1) {
            movie_a.gotoAndPlay("STEP3");
        }
}

:slight_smile:

One more time thanks for your time, I will try that later, but it seems that it will work.

Thanks! :smirk: