A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Loading Random SWFs

  1. #1
    FK Robot Wrangler

    Join Date
    Aug 2000
    Posts
    536

    Loading Random SWFs

    i've been searching and searching for inforation on how to do what i need to do, but haven't been able to find the right combination of features i need.

    here's what i've got:

    i've got an HTML page, and i have 3 Flash movies. the Flash movies are all about 80k, with preloaders. i need to do 2 things:

    1) load a random movie every time the HTML page is refreshed.
    2) cause a new, random, Flash movie to load every 20 second or so.

    i found a reasonably helpful tutorial on how to do this, but unfortunately the randomly called SWFs are NOT utilizing their preloaders. when one SWF is finished playing and the script calls another random SWF, the movie hangs on blank space, ignores the preloader, and plays only after the whole new movie has loaded.

    anyone have any suggestions?

  2. #2
    Resident Shostakovich Scholar
    Join Date
    May 2003
    Location
    Nottingham, UK.
    Posts
    299
    Without using a server-side language like PHP, or complex java code, the best way you can do this is to house the swf files inside a master movie, and use loadMovie for each.

    That way, you can also load a new one after 20 seconds, something traditional languages can't do as they require page transitions, hence AS's unique real-time abilities.

    On the first frame of your master movie:

    movie1 = "some swf1";
    movie2 = "some swf2";
    movie3 = "some swf3";
    myvar = random(3);
    if (myvar == 1) {
    loadMovie(movie1, "level");
    } else if (myvar == 2) {
    loadMovie(movie2, "level");
    } else {
    loadMovie(movie3, "level");
    }

    As for changing after 20 seconds, have a read up in the manual re: the time function etc.
    Last edited by Mitya; 07-24-2003 at 04:50 PM.

  3. #3
    FK Robot Wrangler

    Join Date
    Aug 2000
    Posts
    536
    that code gave me a bunch of errors in the Output window. i tried to fix it, but no luck.

    help?

  4. #4
    Resident Shostakovich Scholar
    Join Date
    May 2003
    Location
    Nottingham, UK.
    Posts
    299
    Well there was an error, but not one that should have given you 'loads of errors', just a typo. I've edited the post and it's now fixed.

    I assume where I put "level" you put a number? By writing 'level' I was just meaning enter the relevant level number, corresponding to the level on which you want the movies to be loaded.

  5. #5
    FK Robot Wrangler

    Join Date
    Aug 2000
    Posts
    536
    sorry, didn't mean to sound like i was pointing fingers.

    the code works like a charm! thank you! i am trying to write some code in on frame 200 that will randomly switch the SWF again. if you have any insight, it would be appreciated.

    The Man With The Happy Client,
    Jaredigital

  6. #6
    FK Robot Wrangler

    Join Date
    Aug 2000
    Posts
    536
    *bump*

    Mitya was kind enough to help me out with my preloader problem. i now have a movie that loads a random SWF every time it starts.

    but this is only half my battle.

    i need a way to make this movie load a random SWF upon initialization, and then continue to load a random SWF every 20 seconds. i have found plenty of information on how to make a linear-progression slideshow, but that is not what i need.

    movie1 = "1.swf";
    movie2 = "2.swf";
    movie3 = "3.swf";
    myvar = random(3);
    if (myvar == 1) {
    loadMovie("1.swf", 0);
    } else if (myvar == 2) {
    loadMovie("2.swf", 0);
    } else {
    loadMovie("3.swf", 0);
    }

    i have tried creating a function, function swapClip (), to hold the instructions i need. but i am sure my syntax is way off since i am not really familiar with writing functions yet. it's not working. i know this can be done (i think) by creating a function that loads a random movie and then using setInterval (swapClip, 20000) to call the function. i just need a little help on the correct scripting.

    anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center