3 Replies Latest reply on Jul 8, 2006 9:56 AM by Rothrock

    Fade in, then fade out...how do i?

    fanmap81 Level 1
      I have this code that loads some images sequentially from a folder on into a movieclip i have on the stage. It works fine, i just need to kno how do i alter it to be able to make the pics fade in, then out over one another instead of just abrubt transitions? Here is the code:

      var yourDesiredDelayInSec:Number = new Number();
      yourDesiredDelayInSec = 3



      slides_xml = new XML();
      slides_xml.onLoad = startSlideShow;
      slides_xml.load("slides.xml");
      slides_xml.ignoreWhite = true;
      //
      // Show the first slide and intialize variables
      var intervalVariable = setInterval(nextImage,(3000 * yourDesiredDelayInSec));

      function startSlideShow(success) {
      if (success == true) {
      rootNode = slides_xml.firstChild;
      totalSlides = rootNode.childNodes.length;
      firstSlideNode = rootNode.firstChild;
      currentSlideNode = firstSlideNode;
      currentIndex = 1;
      updateSlide(firstSlideNode);

      }
      }
      //
      // Updates the current slide with new image and text
      function updateSlide(newSlideNode) {
      imagePath = newSlideNode.attributes.jpegURL;
      slideText = newSlideNode.firstChild.nodeValue;
      loadMovie(imagePath, targetClip);
      }
      //
      // Was the Event handler for 'Next slide' button, now just a function
      function nextImage() {

      nextSlideNode = currentSlideNode.nextSibling;

      if(nextSlideNode == null){
      rootNode = slides_xml.firstChild;
      totalSlides = rootNode.childNodes.length;
      firstSlideNode = rootNode.firstChild;
      currentSlideNode = firstSlideNode;
      currentIndex = 1;
      updateSlide(firstSlideNode);
      }else{
      currentIndex++;
      updateSlide(nextSlideNode);
      currentSlideNode = nextSlideNode;
      }

      };


      Any and all help is appreciated. Thanks
        • 1. Re: Fade in, then fade out...how do i?
          Rothrock Level 5
          I see so many problems with this that the fading part is probably the least of your concerns. Or is this to be delivered over a CD?

          In any event to do things over time (like fade, grow, move, etc.) you have basically two choices: onEnterFrame and setInterval. You can use either of those. Here is what I use:

          _global.fadeIt = function(target, destAlpha, damp) {
          target._visible = true;
          var dAlpha = destAlpha-target._alpha;
          if (Math.abs(dAlpha)>2) {
          target._alpha += dAlpha/damp;
          } else {
          target._alpha = destAlpha;
          if (destAlpha == 0) {
          target._visible = false;
          }
          clearInterval(target.fadeInt);
          }
          };

          And to use it I do this (or there abouts):

          clearInterval(myClip.fadeInt);
          myClip.fadeInt=setInterval(fadeIt, 80, myClip, 0, 3);

          The first line clears the fade interval (if it is already fading) and the second starts calling a new interval for the clip.
          • 2. Re: Fade in, then fade out...how do i?
            fanmap81 Level 1
            this is for the web, i notice in your code i dont see anything for the xml file or path to my images, which im trying to load into my movieclip called targetClip.....is there something im missing here?because when i tried your code nothing happens.
            • 3. Re: Fade in, then fade out...how do i?
              Rothrock Level 5
              Okay since this is for the web you are going to have a lot of problems.

              First loading the images is going to take awhile and I don't see any pre-loader code to wait until the image is loaded. It isn't needed when you are running this from your local computer because the file loads quickly and the flash player actually pauses during the load. But for the web… Instead of using loadMovie, you might want to look into the MovieClipLoader class. That will give you a nice event (onLoadInit) that will happen when the external file is completely loaded.

              Next you have your variable of yourdesireddelayinseconds, but then you multiply it by 3000 in the interval. So 3 seconds is really 9 seconds. Not a problem in-of-itself, but when you come back to this in a year to make changes I almost guarantee you will get confused by it.

              As for the stuff in my code for XML, you are correct. Fading a clip is fading a clip. It doesn't matter if the clip is loaded using XML, placed at authortime, attachMovied, or what have you. Create a brand new flash file and put my code on frame one. Create a movieclip instance called myClip. You should see the clip fade out when you test it.

              This is just the sample code for a fading function. How you use it is up to you.