0 Replies Latest reply on Sep 18, 2009 2:11 PM by theoriginaldrizz

    Problem unloading nested MovieClips and images

    theoriginaldrizz

      I downloaded Weber's Coverflow 2.1 code as a starting point for displaying external content, and I added a combobox to que up a new XML doc pointing to a new set of images. I'm having trouble correctly disposing of the loaded images and loading in the new ones. Anyone sucessfully tried this?

       

      The problem is that I can't unload the nested, dynamically generated 'album covers' and reflections no matter what unload functions I call or no matter what/where I try to target. I have tried deleting from the bottom of the chain on up as well as trying to delete at the very top level container movieClip. Nothing is working here...

       

      I have a couple of questions:

       

      1) The final loading of the images itself into _level0.artworkXX.art uses loadClip, and a MovieClipLoader instance is created and destoyed at each iteration. So my question is:

      If the original mcLoader reference is gone, then unloadClip won't work because it depends on the original loader instance?

       

      BTW: I tried making the Loader instance persistent (global), and that seems to hang the program and crashes it.

       

      2) When you have a dynamically generated container MC with other embeded MCs (artwork & reflection), can you not just destroy the top-level container and all it's contents with one call?

       

      Below, as well as attached, is the slightly modified code (no I didn't break anything just changed some variable names and added some trace statements here and there), and any suggestions or solutions would be greatly appreciated.

       

      Could someone possibly just look at it and then either suggest an approach to a more efficient, and ultimately disposable, means of loading the images or have a means of disposing of the image, reflection and container MC as it it is currently?

       

      TIA,

       

      -Andy

       

      /* loadNext - called by the init function below */
      function loadNext():Void {
      if (!loadedAll) {
        var num:Number = current-1;
        if (infostruc[current-1].loaded) {
         var num:Number = current-Math.floor(distance/2)-1>=0 ? current-Math.floor(distance/2)-1 : 0;
         while (infostruc[num].loaded && num<infostruc.length) {
          num++;
         }
         if (num>=infostruc.length) {
          var num:Number = current-1;
          while (infostruc[num].loaded && num>0) {
           num--;
          }
          if (num<=0) {
           loadedAll = true;
          }
         }
        }
        // BEGIN Image Loading --------------------------------------------------
        var newLoad:MovieClip = this.createEmptyMovieClip("artLoad"+num, this.getNextHighestDepth());
       
        //imagesMCarray.push("artLoad"+num)
       
        newLoad.createEmptyMovieClip("art",newLoad.getNextHighestDepth());
        newLoad._alpha = 0;
        var mc:Object = {};
        mc.number = num;
        var artLoader:MovieClipLoader = new MovieClipLoader();
        artLoader.addListener(mc);
       
        // Image Loading ---------------------------------------------------------------------
        artLoader.loadClip("./"+infostruc[num].art,newLoad.art);
       
        trace("newLoad.art = "+newLoad.art);
       
        mc.onLoadError = function() {
         infostruc[this.number].loaded = true;
         loadNext();
        };
        //------------------------------------------------------------------------------------
        mc.onLoadInit = function(target:MovieClip) {
         target._parent._width = frontCDWidth;
         target._parent._height = frontCDHeight;
         root["_bmd"+this.number] = new BitmapData(target._width, target._height, true, 0x00ffffff);
         root["_ref"+this.number] = new BitmapData(target._width, target._height, true, 0x00ffffff);
         root["_bmd"+this.number].draw(target);
         var mc:MovieClip = target._parent.createEmptyMovieClip("gradient_mc", target._parent.getNextHighestDepth());
         matrix = new Matrix();
         matrix.createGradientBox(target._width,target._height,reflectionRotation/180*Math.PI,0,0) ;
         mc.beginGradientFill(reflectionFillType,reflectionColors,reflectionAlphas,reflectionRatio s,matrix,reflectionSpreadMethod,reflectionInterpolationMethod,reflectionFocalPointRatio);
         mc.moveTo(0,0);
         mc.lineTo(0,target._height);
         mc.lineTo(target._width,target._height);
         mc.lineTo(target._width,0);
         mc.lineTo(0,0);
         mc.endFill();
         target._alpha = 50;
         target._parent.beginFill(reflectionBackgroundColour);
         target._parent.moveTo(0,0);
         target._parent.lineTo(0,target._height);
         target._parent.lineTo(target._width,target._height);
         target._parent.lineTo(target._width,0);
         target._parent.lineTo(0,0);
         target._parent.endFill();
         root["_ref"+this.number].draw(target._parent);
         infostruc[this.number].loaded = true;
         target._parent.removeMovieClip();
         updateInfo();
         loadNext();
        };
      }
      }
      /* INIT */
      function init(Void):Void {
       
      for (var i in infostruc) {
        loader.clear();
        loader.gradient_mc.removeMovieClip();
        loader.attachMovie("default","art",1);
        loader._width = frontCDWidth;
        loader._height = frontCDHeight;
        this["_bmd"+i] = new BitmapData(loader._width, loader._height);
        this["_ref"+i] = new BitmapData(loader._width, loader._height);
        this["_bmd"+i].draw(loader);
        var mc:MovieClip = loader.createEmptyMovieClip("gradient_mc", loader.getNextHighestDepth());
        matrix = new Matrix();
        matrix.createGradientBox(loader._width,loader._height,reflectionRotation/180*Math.PI,0,0) ;
        mc.beginGradientFill(reflectionFillType,reflectionColors,reflectionAlphas,reflectionRatio s,matrix,reflectionSpreadMethod,reflectionInterpolationMethod,reflectionFocalPointRatio);
        mc.moveTo(0,0);
        mc.lineTo(0,loader._height);
        mc.lineTo(loader._width,loader._height);
        mc.lineTo(loader._width,0);
        mc.lineTo(0,0);
        mc.endFill();
        loader.art._alpha = reflectionAlpha;
        loader.beginFill(reflectionBackgroundColour);
        loader.moveTo(0,0);
        loader.lineTo(0,loader._height);
        loader.lineTo(loader._width,loader._height);
        loader.lineTo(loader._width,0);
        loader.lineTo(0,0);
        loader.endFill();
        this["_ref"+i].draw(loader);
      }
      for (var i:Number; i<=infostruc.length; i++) {
        //var cArt:MovieClip = this.createEmptyMovieClip("art"+this.getNextHighestDepth(), this.getNextHighestDepth());
        //var rArt:MovieClip = this.createEmptyMovieClip("reflection"+(this.getNextHighestDepth()-1), this.getNextHighestDepth());
        var cArt:MovieClip = this.createEmptyMovieClip("art"+i, this.getNextHighestDepth());
        var rArt:MovieClip = this.createEmptyMovieClip("reflection"+i, this.getNextHighestDepth());
        rArt.id = cArt.id=rArt.cid=cArt.cid=Number(i)+1;
        cArt.DistortImage(this["_bmd"+cArt.id]);
        controlTheObject(cArt);
        rArt.DistortImage(this["_ref"+cArt.id]);
        controlTheObject(rArt);
        var tmpFilter:BlurFilter = new BlurFilter(reflectionBlurX, reflectionBlurY, reflectionQuality);
        rArt.filterArray = [];
        rArt.filterArray.push(tmpFilter);
        rArt.filters = rArt.filterArray;
      }
      distance = Number(i);
      mask.removeMovieClip();
      loader.removeMovieClip();
      scrollBar.swapDepths(1101);
      loadNext();
      updateInfo();

       

      }
      /* END INIT */