Adapted Kirupa random loading background

I’ve just followed the Kirupa random loading background tutorial and I am getting a syntax error in the actionscript. I want the random loading swf’s to load on top of the background, so I made the top layer the “location” movie clip with the actions to randomly load movie. The exact syntax error message I’m getting is as follows…Scene=Scene 1, Layer=location, Frame=1: Line 2: The JavaScript ‘switch’ construct is not supported
switch (choice) {

Can anyone tell me what I need to change the ‘switch’ contruct to so I can get this to work?

Thanks in advance,
Telegirl

what does your code look like?
try using if-else instead of switch…

my code…
choice = Math.round(Math.random()*5);
switch (choice) {
case 0 :
location.loadMovie(“quote0.swf”);
break;
case 1 :
location.loadMovie(“quote1.swf”);
break;
case 2 :
location.loadMovie(“quote2.swf”);
break;
}

I tried exchanging the ‘switch’ with ‘else-if’ and the code started to generate more error messages.

choice = Math.round(Math.random()*5);
if (choice==0) {
location.loadMovie(“quote0.swf”);
break;
} else if (choice==1) {
location.loadMovie(“quote1.swf”);
break;
} else if (choice==2) {
location.loadMovie(“quote2.swf”);
break;
}

i know there’s a better way to do it, but this will work. :stuck_out_tongue: Not sure what the break’s are for, but i kept them in.

try

choice = Math.round(Math.random()*5);
location.loadMovie("quote"+choice+".swf");

That won’t work if you only want things to happen when choice = 0, 1 or 2 as in the code, although I suspect that you do, and that that code was for demonstration purposes only.

Jack_knife,

I tried your script and it isn’t generating any errors…however when I test the movie it’s not loading the quote swf’s either. I published the movie, the quote swf’s are in the same folder, I’ve enabled simple actions too, so I don’t understand why this isn’t working now. I followed the Kirupa tutorial for random loading background exactly and have exchanged the action script from that with the one you posted. I wonder at this point if I am doing something else wrong. This is getting very frustrating…

[AS]
choice = Math.round(Math.random()*5);
switch (choice) {
case 0 :
location.loadMovie(“quote0.swf”);
break;
case 1 :
location.loadMovie(“quote1.swf”);
break;
case 2 :
location.loadMovie(“quote2.swf”);
break;
case 3:
break;
}
[/AS]

Post your fla if you have more problems. You might be putting it in the wrong place or something similar.

By the way, break is a statement used to execute the loop or switch statement currently running. For example, if you have a for loop running and it hits the command break, it will immediately exit the loop.

“Switch” is causing me error messages and won’t work.

The zipped files can be downloaded at http://www.hawaiiancow.com/flash_files.html . For some reason the flash movie file needs to be opened from Flash and then saved in Flash. I don’t understand why, but this is the first time I’ve put files up on a site to download…I must be doing something wrong…I’m very new at all of this…

Thanks,
Telegirl

plz upload the .FLA files, not the .SWF files or zips

Okay, all the .fla files are uploaded to the site… http://hawaiiancow.com/flash_files.html

thanks, that will help a ton, i’ll look at them tomorrow, right now i have to write a paper… :frowning:

Thanks so much…I really appreciate it! Good luck on your paper.

thanks… im gonna need it… lol :stuck_out_tongue:

Dont forget to give your location mc an instance name of location.[AS]location.loadMovie(“quote”+Math.round(Math.random()*5)+".swf");[/AS]

Hahaha…thank you So much…that’s Exactly what was missing! Time for me to do a Homer Simpson-esque “D’oh”! The movie’s loading the random quotes beautifullly now! My most profound appreciation to everyone for their help!!! :slight_smile:

welcome :wink: