1 Reply Latest reply on May 25, 2007 11:35 AM by dfm_

    XML Preloader

    mikecoleman79
      Hi there,

      I wonder if anyone can help me out with this problem I have. I’m fairly experienced in flash but this I just can’t get my head around!

      I’m trying to make a header of a webpage load random images from an xml file. This I can do fine but as the images are good quality they tend to take a while to load. Is there anyway that I can have a preloader appear when each file is loading?

      This is how my code looks:

      slideshow_xml = new XML();
      slideshow_xml.load("images.xml");
      slideshow_xml.ignoreWhite = true;
      slideshow_xml.onLoad = parseXML;

      var container_mc = this.createEmptyMovieClip("container", 0);
      container_mc.createEmptyMovieClip("loader1_mc", 1);
      container_mc.createEmptyMovieClip("loader2_mc", 2);
      var mc_Loader1:MovieClipLoader = new MovieClipLoader();
      var mc_Loader2:MovieClipLoader = new MovieClipLoader();
      var listener1:Object = new Object();
      listener1.onLoadInit = function() {
      _root.loadedPic = picturePicker();
      trace(_root.loadedPic);
      mc_Loader2.loadClip(_root.loadedPic, container_mc.loader1_mc);
      var fadeOut = new mx.transitions.Tween(container_mc.loader2_mc, "_alpha", mx.transitions.easing.Regular.easeOut, 1000, 0, 5, true);
      };
      mc_Loader1.addListener(listener1);
      function fadeImageNext() {
      mc_Loader1.loadClip(_root.loadedPic, container_mc.loader2_mc);
      }

      function parseXML(success) {
      if (success) {
      _global.imageArray = new Array();
      var root = this.firstChild;
      _global.numPause = Number(this.firstChild.attributes.timer*5000);
      _global.order = this.firstChild.attributes.order;
      _global.looping = this.firstChild.attributes.looping;
      _global.fadetime = Number(this.firstChild.attributes.fadetime);
      _global.xpos = Number(this.firstChild.attributes.xpos);
      _global.ypos = Number(this.firstChild.attributes.ypos);
      var childPtr = root.lastChild;
      var count = 0;
      while (childPtr.nodeName != null) {
      imageData = new Object();
      imageData.path = childPtr.attributes.path;
      _global.imageArray[count] = imageData;
      childPtr = childPtr.previousSibling;
      ++count;
      }
      container_mc._x = _global.xpos;
      container_mc._y = _global.ypos;
      _root.loadedPic = picturePicker();
      _root.fadeImageNext();
      slideTimer = setInterval(_root.fadeImageNext, numPause);
      }
      }
      function picturePicker() {
      var nextPath = undefined;
      if (_global.order == "random") {
      while (randomNum == randomNumLast) {
      randomNum = Math.floor(Math.random()*_global.imageArray.length);
      }
      nextPath = _global.imageArray[randomNum].path;
      randomNumLast = randomNum;
      } else if (_global.order == "sequential") {
      if (p == undefined || p == _global.imageArray.length && _global.looping == "yes") {
      p = random(imageArray.length);
      }
      nextPath = _global.imageArray[p].path;
      p++;
      }
      if (nextPath != undefined) {
      return nextPath;
      }
      }

      Please can someone out there help me?

      Mike
        • 1. XML Preloader
          dfm_ Level 1
          ///allGlazed -> pictures urls
          var allGlazed:Array = new Array("image1.jpg", "image2.jpg", "image3.jpg");
          var bigPicLoader:MovieClipLoader = new MovieClipLoader();
          var bigPicObject:Object = new Object();
          bigPicLoader.addListener(bigPicObject);
          for (i=0; i<positionGlezedX_florWall.length; i++) {
          bigPicLoader.loadClip(allGlazed , walls_mc["pictureHolder"+(i+1)]);
          }
          var loadedParts:Number = 0;
          bigPicObject.onLoadInit = function() {
          loadedParts++;
          if (loadedParts == allGlazed.length) {
          //all images are loaded
          }
          };

          -> load images. It must be sth like that.