A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: load and crossfade images from folder

  1. #1
    Occasionally Awake
    Join Date
    Aug 2000
    Posts
    42

    load and crossfade images from folder

    Hi there,

    The task
    ---------
    To get a slideshow of images to load from a folder, and to crossfade them as they appear. Attempting to do this with AS only in case images ever change, plus it would be a good tool to re-use. Images should remain about 2s on screen (can be a variable).

    How far I got!
    I've got as far as fading-in, then fading-out a single image. Independently I can loop through all the images in the folder successfully one at a time. What I canna do is get the two scripts to work together, and night has fallen already !

    The following code on the main timeline is what I'm working with, with one static movieclip:
    The fade script:
    ----------------
    code:
    _root.fadeInc = 5;
    _root.fade = 0;
    loadMovie("eye/0046.jpg","imageHolder_mc");

    function imageFader() {
    var nTimeNow = getTimer();
    if (nTimeNow <= 1000) {
    trace (_root.fade);
    if (_root.fade <= 99) {
    _root.fade += _root.fadeInc;
    imageHolder_mc._alpha = _root.fade;
    trace("fading in now: alpha(" + _root.fade + ") at time: " + nTimeNow);
    }
    } else if (nTimeNow >= 2000) {
    trace (_root.fade);
    if (_root.fade > 0) {
    _root.fade -= _root.fadeInc;
    imageHolder_mc._alpha = _root.fade;
    trace("fading out now: alpha(" + _root.fade + ") at time: " + nTimeNow);
    } else if (_root.fade <= 0) {
    trace ("reached 0 alpha, remove clip and stop timer");
    clearInterval(nFaderInterval);
    unloadMovie("imageHolder_mc");
    nTimerNow = 0;
    }
    }
    }
    // this is the thing that sets it all off
    var nFaderInterval:Number = setInterval(imageFader, 10);



    -------------------
    And the following does the loop through all files:
    -------------------
    _root frame 1 (preload frame)
    ------
    // for images numbered 1 to 168 in a folder
    var aImageNames:Array = new Array();
    for (var i:Number = 1; i < 168; i++) {
    aImageNames[i] = i;
    }

    var imageNumber = 1;
    var maxNumber = aImageNames.length;

    ---------
    _root frame 2 (after preloader) contents
    ---------
    function nextImage() {
    if (imageNumber < maxNumber) {
    trace("loading the following movie: " + aImageNames[imageNumber]);
    unloadMovie("imageHolder_mc");
    loadMovie("eye/" + aImageNames[imageNumber] + ".jpg", "imageHolder_mc");
    imageNumber++;
    } else {
    trace ("reached the max number of images, clear the timer");
    clearInterval(nMovieInterval);
    }
    }
    var nMovieInterval:Number = setInterval(nextImage, 1000);
    ---------------

    So I got all tied up in my setIntervals and where I could put them - I only need the fader check to occur AFTER each image has loaded, not every 10 ms.
    That will do for a start, then the task is to get the images loaded into two movieclips so they crossfade. I can handle that bit as long as the fading script is working.

    Please can anybody help me with this probably simple problem! I've had a search with no results yet but am still looking, I'm stuck in a rut!

    If you need the FLA or SWF samples just shout.

    Many thanks,

    Alun
    Last edited by alun; 01-29-2005 at 02:53 PM.

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    I would made it this way
    Attached Files Attached Files

  3. #3
    Occasionally Awake
    Join Date
    Aug 2000
    Posts
    42
    Sergwiz, fantastic! Works a treat.

    I've just been playing with the Component by Alessandro Perroni at
    http://www.alessandroperrone.com/
    which is good, but how much better to be able to work through it from your helpful file, and in a much neater way.

    Will have to wait until morning (UK time) to work out your code properly, but I guess onEnterFrame is the key. I always get confused about timers.

    Thanks again,

    A

    Originally posted by sergwiz
    I would made it this way

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Nice pictures!

  5. #5
    Occasionally Awake
    Join Date
    Aug 2000
    Posts
    42
    Originally posted by oldnewbie
    Nice pictures!
    I should hope he took them himself

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