0 Replies Latest reply on Dec 11, 2009 1:05 PM by Techmaniac

    Array not resizing or any simple solution

    Techmaniac

      I'm using a script that I've modified to create rotating promotions for a site.  It reads the SWF file names from an XML file and loads accordingly, with a fade in and out to rotate the next promotion.  Now I want to add and attribute to the XML entries for expiration of content.  The thing is, it won't let me remove/resize the array.  ARGH!

       

      #include "ConvertStringDate.as"
      import flash.filters.BlurFilter;
      var currentDate = new Date();
      var expires:Array = Array();
      var timed:Array = Array();
      var dateDifference:Number;
      stop();
      counter=-1;
      //Check if the GET parameter XMLfile is set, if not use a default file
      if(_root.XMLfile==undefined || _root.XMLfile==""){
          _root.XMLfile="imagelist.xml";
      }
      //Fix the size of the content
      Stage.scaleMode = "noScale";
      //There are 2 movie clips used, and they are rotated
      currentTop=0;
      //Get the percentage loaded of the next image
      function getPercentLoaded() {
          return (100*eval("displayImage"+currentTop).getBytesLoaded()/eval("displayImage"+currentTop).get BytesTotal());
      }
      //Set the current image to the next image
      function nextListImage(){
          trace("In next image list function");
          if (typeof imageList[currentTop] == "string"){
              currentImage++;       
              return currentImage;
          }else{
              currentImage=(currentImage+1)%imageList.length;
              trace("currentImage = " + currentImage);
              return currentImage;
          }
      }
      //Set the current image to the previous image
      function previousListImage(){
          currentImage=(currentImage-1)%imageList.length;
          if(currentImage<0){
              currentImage=imageList.length-1;
          }
          return currentImage;
      }
      //Reset the delay counter, swap the images in depth, and make the top invisible
      function nextImage(){
          counter=60;
          currentTop=(currentTop+1)%2;
          eval("displayImage"+currentTop).swapDepths(eval("displayImage"+((currentTop+1)%2)));
          eval("displayImage"+currentTop)._alpha=0;
          return currentTop;
      }
      function skipImage(image){
          trace("The passed var = " + image);
          if(image="foo"){
              counter=60;
              currentTop=currentTop;
              loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
          }
      }               
             
      //Scale the image to fit the window
      var imageList:Array = Array();
      var imgArray:Array = Array();
      var expDateTime:Array = Array();
      var todaysDate:Date = new Date();
      var myXml:XML = new XML();
      myXml.ignoreWhite = true;
      myXml.load(_root.XMLfile);
      //Load the xml file and parse it
      myXml.onLoad = function() {
          currentImage=myXml.childNodes[0].childNodes.length-1;
          for(imageIndex=0; imageIndex<myXml.childNodes[0].childNodes.length; imageIndex++){
              imageList[imageIndex]=myXml.childNodes[0].childNodes[imageIndex].childNodes[0].childNodes [0];
              expires[imageIndex] = imageAttributes[imageIndex]=myXml.childNodes[0].childNodes[imageIndex].childNodes[0].attr ibutes.expires;
              timed[imageIndex] = imageAttributes[imageIndex]=myXml.childNodes[0].childNodes[imageIndex].childNodes[0].attr ibutes.timed;
          }
          for(imageIndex=0;imageIndex<imageList.length;imageIndex++){       
              if (expires[imageIndex]!=null){
                  expDateTime[imageIndex]=ConvertStringDate(expires[imageIndex],timed[imageIndex]);
                  dateDifference = currentDate.getTime() - expDateTime[imageIndex].getTime();       
              }else{
                  dateDifference = -1;
              }       
              if (dateDifference > 0 ) {
                  imgArray[imgArray.length] = imageIndex;
              }       
          }
          for(i=0;i<imgArray.length;i++){
                  imageList.splice(imgArray[i],1,"foo");           
          }
              for(i=0;i<imageList.length;i++){
                  trace(imageList[i]);           
              }
          //reset the delay counter
          counter=60;
          //currentImage = 0;
          //load an image
          loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
      }
      onEnterFrame=function(){
          counter--;
          //display the total slides and the current slide number
          promo_Numbers.text = (currentImage + 1) + " | " + (imageList.length - imgArray.length);
          //if the xml file has loaded
          if(imageList.length>0 && counter>(-1)){
              //if the delay counter hits 0, load the next image
              if(counter==0){
                  trace ("Another coming..");
                  loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
              }   
              //start the transition after the next image has loaded
              if(eval("displayImage"+currentTop)._alpha<100 && eval("displayImage"+currentTop).getBytesLoaded()==eval("displayImage"+currentTop).getByte sTotal() && eval("displayImage"+currentTop).getBytesLoaded()>0 ){
                  //fade one in and one out
                  eval("displayImage"+currentTop)._alpha+=20;
                  eval("displayImage"+((currentTop+1)%2))._alpha-=20;   
                  //image is still loading
              }else if(eval("displayImage"+currentTop).getBytesLoaded()!=eval("displayImage"+currentTop).getB ytesTotal()){
                  counter=60;
              }
          }
      }

       

      An XML entrie looks like this:

      <?xml version="1.0" encoding="iso-8859-1"?>
      <images>
        <image>
            <url>../flash/videoContest_MC.swf</url>
        </image>
        <image>
          <url expires="11/13/2009" timed="14:15">../flash/tackle_MC.swf</url>
        </image>

       

      The first one is the simple, and the second has the attributes for expiring an entry.  The problem is I can't get the array to eliminate a member of the array if the expires attribute has passed.  I also haven't been able to sub the entrie with a string and ignore the entry.  It still looks for the entry and throws an error that it can't find the "foo" SWF.  HELP!  I'm frustrated by trying to solve this conundrum myself for so many weeks.