PDA

View Full Version : Adapted Kirupa random loading background



telegirl
September 1st, 2003, 06:51 PM
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) {

telegirl
September 1st, 2003, 06:54 PM
Can anyone tell me what I need to change the 'switch' contruct to so I can get this to work?

Thanks in advance,
Telegirl

ahmed
September 1st, 2003, 06:55 PM
what does your code look like?
try using if-else instead of switch..

telegirl
September 1st, 2003, 06:58 PM
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;
}

telegirl
September 1st, 2003, 07:51 PM
I tried exchanging the 'switch' with 'else-if' and the code started to generate more error messages.

Jack_Knife
September 2nd, 2003, 03:45 AM
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. :P Not sure what the break's are for, but i kept them in.

ahmed
September 2nd, 2003, 03:59 AM
try
choice = Math.round(Math.random()*5);
location.loadMovie("quote"+choice+".swf");

Jack_Knife
September 2nd, 2003, 04:02 AM
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.

telegirl
September 2nd, 2003, 12:17 PM
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...

grandsp5
September 2nd, 2003, 05:05 PM
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;
}



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.

telegirl
September 2nd, 2003, 10:07 PM
"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

Yeldarb
September 2nd, 2003, 10:13 PM
plz upload the .FLA files, not the .SWF files or zips

telegirl
September 2nd, 2003, 10:57 PM
Okay, all the .fla files are uploaded to the site... http://hawaiiancow.com/flash_files.html

Yeldarb
September 2nd, 2003, 11:12 PM
thanks, that will help a ton, i'll look at them tomorrow, right now i have to write a paper... :(

telegirl
September 2nd, 2003, 11:15 PM
Thanks so much...I really appreciate it! Good luck on your paper.

Yeldarb
September 2nd, 2003, 11:19 PM
thanks... im gonna need it... lol :P

claudio
September 3rd, 2003, 03:35 AM
Dont forget to give your location mc an instance name of location.location.loadMovie("quote"+Math.round(Math.random()*5)+".swf");

telegirl
September 3rd, 2003, 12:38 PM
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!!! :-)

claudio
September 3rd, 2003, 12:45 PM
welcome ;)