4 Replies Latest reply on Dec 5, 2007 2:31 AM by purple_am

    Preloading from XML data

    purple_am Level 1
      Hey guys,

      Am stuck and need some help. My situation is as follows :

      I have an XML from which I get some urls passed into flash. (urls are path to images)
      And I have 3 movieclips sitting on the stage waiting to hold the images.

      I need to preload all the 3 images on the first frame of my movie before it starts playing.
      All I have been able to do is this :
      ////////////////////////////////////////////////////////////////////////
      upComing = new XML();
      upComing.ignoreWhite = true;
      upComing.load("xml/hupcoming.xml");
      upComing.onLoad = function(success) {
      image = [];
      xmlNode = this.firstChild;
      totalNumImages = xmlNode.childNodes.length;
      for (i=0; i<totalNumImages; i++) {
      image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;

      }
      trace(image[0]);
      trace(image[1]);
      trace(image[2]);
      };
      ////////////////////////////////////////////////////////////////////////
      var imgHolders:Array = [holder1, holder2, holder3];

      I have been looking at the MovieClipLoader but cant figure it out.

      Anyone around who can help me complete this.

      Thanks.
        • 1. Re: Preloading from XML data
          crazyjoemilan Level 2
          //creates a movieClip to load the image into
          var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());

          //creates a movieClipLoader (to watch the loading for you)
          var mcLoader:MovieClipLoader = new MovieClipLoader();

          //add a listener to watch the loading
          mcLoader.addListener(this);

          //loadMovie "YourImage.jpg" into container
          mcLoader.loadClip("YourImage.jpg", container);

          //once its loaded it will trace for you
          function onLoadInit(mc:MovieClip) {
          trace("onLoadInit: " + mc);
          }

          does that help?
          • 2. Re: Preloading from XML data
            purple_am Level 1
            The code helps for sure ... but instead of creating the movieclip on the fly i want to load it in MCs already on the stage.

            I prefer not to create MCs on the fly cause i will be animating them.

            • 3. Re: Preloading from XML data
              crazyjoemilan Level 2
              Just kill "var container ..."

              And replace "container" with your mc name (from the stage) in the loadClip() function.
              • 4. Re: Preloading from XML data
                purple_am Level 1
                well here is what i did
                ////////////////////////////////////////////////////////////////////////
                slideContent = new XML();
                slideContent.ignoreWhite = true;
                slideContent.load("xml/slideContent.xml");
                slideContent.onLoad = function(success) {
                image = [];
                xmlNode = this.firstChild;
                totalNumImages = xmlNode.childNodes.length;
                for (i=0; i<totalNumImages; i++) {
                image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
                mcLoader.loadClip(image[0],img_right_mc);
                mcLoader.loadClip(image[1],slideContainer_mc.slideContent_mc);
                }
                };
                ////////////////////////////////////////////////////////////////////////
                var mcLoader:MovieClipLoader = new MovieClipLoader();
                ////////////////////////////////////////////////////////////////////////
                mcLoader.addListener(this);
                ////////////////////////////////////////////////////////////////////////
                function onLoadInit(mc:MovieClip) {
                gotoAndStop(2);
                }
                ////////////////////////////////////////////////////////////////////////

                Its working fine but am not sure if its the right way of coding it.