dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: preload random images in main movie every 10 seconds after load complete

  1. #1

    preload random images in main movie every 10 seconds after load complete

    Hi there,
    I am working on a flash web site and I have a half decent code for it but there are some bugs i cant figure out.
    www.fadlighting.com/test
    The following is the concept:
    Load a random image from the folder on the server. Build preloader that showes size of image and percent remaining to load image. Wait 10 seconds and load new random image.

    So far I was able to do so with the expert help of the Bible for Flash.
    The following is the code i scrached together, This portion is at frame 1 of main time line
    function loadFile() {

    images = 13;
    directory = "http://www.fadlighting.com/test/random/image_";
    image = directory add Math.ceil(Math.random()*images) add ".jpg"
    intro_holder.loadMovie(image);
    var loadObj = intro_holder;

    var initObject = {
    _x: intro_holder._x +590 ,
    _y: intro_holder._y +240 ,
    target: loadObj,
    loadExit: null
    };

    _root.attachMovie("loader","loader",2, initObject);
    updateAfterEvent();
    setInterval(loadFile, 10000);


    }

    loadFile();
    // setInterval(loadFile, 10000);

    // intro_holder.unloadMovie();
    // updateAfterEvent();

    the following code is in a Movie Clip called intro_holder in the library on frame 1 of its timeline
    function checkLoad(obj) {
    var lBytes = target.getBytesLoaded();
    var tBytes = target.getBytesTotal();
    var percentLoaded = Math.floor((lBytes/tBytes)*100);
    bar._xscale = percentLoaded;
    percent.text = Math.floor(percentLoaded)+"% of "+Math.floor(tBytes/1024)+"KB loaded.";
    if (lBytes>=tBytes && tBytes>0) {
    if (count>=12) {
    clearInterval(checkProgress);
    _parent[loadExit]();
    obj.removeMovieClip();
    } else {
    count++;
    }
    }
    updateAfterEvent();
    }
    checkProgress = setInterval(checkLoad, 100, this);
    stop();

    the code works but it does not wait for the image to be loaded before starting countdown for 10 seconds... and in between loads something is off... uhmmmm I can email fla if interested to long to post.

    Thanks!!!

    __________________
    Anthony Palermo
    aderium@bellsouth.net
    http://www.aderium.com
    Anthony Palermo
    aderium@bellsouth.net
    http://www.aderium.com

  2. #2
    Member
    Join Date
    Dec 2002
    Location
    Luxembourg
    Posts
    76
    It 'does not wait for the image to be loaded before starting countdown for 10 seconds' because you don't ask it to.

    You attach the movie, then set the Interval immediately.
    Code:
    _root.attachMovie("loader","loader",2, initObject);
    updateAfterEvent();
    setInterval(loadFile, 10000);
    Remove the 'setInterval' line, and past it into your preloader, in the 'if completely loaded' part.

    That should make it work...
    ... nads ...

  3. #3
    I remove the setInterval line from the main action and paste it into the preloader but I am obtaining no result.
    Were specifically would i pout it and is there any reference code I need to pass on from the main action?

    Thanks!
    Anthony Palermo
    aderium@bellsouth.net
    http://www.aderium.com

  4. #4
    gskinner.com
    Join Date
    Feb 2002
    Location
    N.America
    Posts
    455
    FYI:

    I have an FLA that will preload images in the background, and then fade them over the current image at regular intervals. It's very easy to implement, and even if id doesn't suit your needs you could always modify it, or use the code that works for you.

    If you're interested in checking it out/downloading it:
    http://gskinner.com/go.asp?to=gPhotoFader

    Cheers,
    Grant.
    http://gskinner.com/ - Flash application development and source code
    http://gmodeler.com/ - free online uml diagramming and documentation tool

    Team Macromedia Voluteer for Flash.

  5. #5

    Thanks For The fade out!

    Hey Man,

    I looked at the swf.. havn't seen the fla yet but looks like there is a xml file!!! I ll tell you later how it whent.

    Thanks !

    P.S. I still would like for you to look at my code and understand what's buggy about it... let me know.

    Anthony
    Anthony Palermo
    aderium@bellsouth.net
    http://www.aderium.com

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