A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Call Random Flash Movies from HTML

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Posts
    130

    Call Random Flash Movies from HTML

    When a user comes to my site I would like to show a different random movie each time. I have the code to do this in flash,

    // create an array of the filenames that can be loaded (minus the .swf extension)
    var movies = ["flash1", "flash2"];
    var index = Math.floor(Math.random() * movies.length);
    // load a random movie from the array
    loadMovieNum(movies[index] + ".swf", 1);


    but it doesn't work when it's implemented on-line. Therefore I would like to code the random retrieves of the flash movies from HTML. Does anyone know how to accomplish this? Thank you


    This the link to my current page where I have tried to get the code to work within flash:

    http://www.energykitchen.com/testmain3.php
    Last edited by laidback; 01-26-2006 at 02:21 PM.

  2. #2
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    You are having a path issue:
    your main swf is located at "swf/random-flash.swf";
    Any other path to a swf file you load is realative to your embedding html-page,
    not to your "random-flash.swf"

    if you change your code to:
    loadMovieNum("swf/"+movies[index] + ".swf", 1);

    it should work online (but no more in authoring environment)
    My letters on the F1 key have faded, how are yours today?

  3. #3
    Senior Member
    Join Date
    Aug 2004
    Posts
    130
    Brilliant!!! It worked. Thank you so much.

    If I could bother you with one more question - there is a lag as to when the Random movies load - is there any way to cut this lag out?

    Thanks again.

  4. #4
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    What do you mean by "lag" ... a little delay before it shows up?
    That depends mostly on the design on the randomly loaded swfs..
    You can't do anything against real lag, the time until the server
    sends the file..
    My letters on the F1 key have faded, how are yours today?

  5. #5
    Senior Member
    Join Date
    Aug 2004
    Posts
    130
    Is there a quicker way to load it? Maybe by assigning the random movie names in the HTML. Is this possible?

  6. #6
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Of course you could program that random function in javascript,
    and load the random movie directly, but it is a bit more complicated...

    I did a flash, where i pass some variables to the flash embedding section,
    you don't need it that complicated, but i hope i helps you for a start..
    see source code of [url removed]

    But if i were you, i'd stick to the current version, your random-flash.swf
    is just 1kb, you won't win much... probably you should optimized
    the flashes that gets loaded into it a bit that should help much more..

    i have almost no lag, but i got 2mBit...
    Last edited by McUsher; 11-13-2006 at 01:13 PM.
    My letters on the F1 key have faded, how are yours today?

  7. #7
    Senior Member
    Join Date
    Aug 2004
    Posts
    130
    Thank you - I'll try and optimize the other flashes and maybe that will work better

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