7 Replies Latest reply on Nov 15, 2009 1:05 PM by Ned Murphy

    how I remove previous MC created with createmovieClip() and attachMovie()

    cosmicvibs

      Hello.

      i have another problem today, :-)

      my little application contain a combobox and a MC "filmstrip" in my _root. the combobox work with an xml file containing links to other xml files. Inside my MC "filmstrip" i have a script loading with a for loop the xml file selected in the combobox on the _root .

      In this loop i createEmptyMovieClip an attachMovies with the data  of the xml selected.

      evrything works exept that evrytime i change my selection in the combobox it load the data  on top of the previous load.

      I would like to delete  the previous load before load the new one... if someone can help me???

      On my scene 1st frame i have only a code for scroll the movieclip filmstrip but i think is not nescessary that i show it.

      here is the code inside the MC fimlstrip (sorry but i put all the code). i attach an example aswell

       

      var link1:Array = new Array();
      var url:String;
      var theUrl:String;
      var whoOn:Number;
      whoOn = 1;
      
      //load the  xml containing the link for T.Load() function
          var x:XML = new XML();
          x.ignoreWhite = true;
      
       x.onLoad = function(success) {
              var photos:Array = this.firstChild.childNodes;
              for (i=0; i<photos.length; i++) {
                  link1.push(photos[i].attributes.link1);
              }
              url = link1[whoOn];
              theUrl = url;
              _root.filmstrip.Tload(theUrl);
              _root.lengthscroll(theUrl);
          };
          x.load("category.xml");

       

      
      //create the Listener object
      var cbListener:Object = new Object();
      
      //create tee change function
      cbListener.change = function(event_obj:Object) {
          if (_root.select.selectedItem.label == "Last updated") {
              whoOn = 0;
          } else if (_root.select.selectedItem.label == "Special") {
              whoOn = 1;
          }
          trace(_root.select.selectedItem.label);
          url = link1[whoOn];
          trace("url is "+_root.filmstrip.url);
          theUrl = url;
          _root.lengthscroll(theUrl);
          Tload(theUrl);// set the url to load in the T.load()
      };
      _root.select.addEventListener("change",cbListener);
      
      function Tload(theUrl) {//function that load the url selected in the combobox
          var T:XML = new XML();
          T.ignoreWhite = true;
          var thumb:Array = new Array();//create array
          var thTxt:Array = new Array();
          var DescTXT:Array = new Array();
          var priceTXT:Array = new Array();
          var linkTXT:Array = new Array();
          var Modelink = "http://www.windi.no/catalog/advanced_search_result.php?keywords=";//1st part of the link for when you click on the tumbnails
          var Spc = 0;// space between thumbnail default 0
          var posX = 0;// thumbnail position x
          var posY = 0;//thumbnail 1st position y
          var tl:MovieClip = this;
          var whoIsOn:Number;
          whoIsOn = 0;
          T.onLoad = function(xml) {
              var photos:Array = this.firstChild.childNodes;
              //loop the php Xml for the thumbnail
              for (i=0; i<photos.length; i++) {
                  var Num = i+1;
                  var WhoIsOn = Num;
                  var TXTCLIP = "TXTCLIP"+Num;
                  var TXTCLIP2 = "TXTCLIP2"+Num;
                  var TXTCLIP3 = "TXTCLIP3"+Num;
                  var Clp_name = "clip"+Num;
                  var Bt_name = "Bt"+Num;
                  var container = (container+Num);
                  //put each attributs of thumbnail for each photos node 
                  thTxt.push(photos[i].attributes.thumbtext);
                  thumb.push(photos[i].attributes.thumbnail);
                  DescTXT.push(photos[i].attributes.thumbdesc);
                  priceTXT.push(photos[i].attributes.thumbprice);
                  linkTXT.push(photos[i].attributes.thumbmodel);
                  _root.Text_Thumbnail(thTxt[whoIsOn]);
                  _root.bigphotos.loadMovie(thumb[whoIsOn],1);
                  var fullink = (Modelink+linkTXT[i]);//the 2nd part of the "Modelink"
      
                  //display Tiles
                  var TXT:MovieClip = tl.attachMovie("TXTCLIP", TXTCLIP, tl.getNextHighestDepth());
                  TXT._x = posX+120;
                  TXT._y = posY+Spc+13;
                  TXT.titleTXT.text = thTxt[i];
      
                  //desccription
                  var TXT2:MovieClip = tl.attachMovie("TXTCLIP2", TXTCLIP2, tl.getNextHighestDepth());
                  TXT2._x = posX+120;
                  TXT2._y = posY+Spc+30;
                  TXT2.titleTXT.text = DescTXT[i];
      
                  // display prices
                  var TXT3:MovieClip = tl.attachMovie("TXTCLIP3", TXTCLIP3, tl.getNextHighestDepth());
                  TXT3._x = posX+120;
                  TXT3._y = posY+Spc+90;
                  TXT3.titleTXT.text = priceTXT[i];
      
                  //display thumbnails
                  var container:MovieClip = tl.createEmptyMovieClip(Clp_name, tl.getNextHighestDepth());
                  container.loadMovie(thumb[i],1);
                  container._yscale = 30;
                  container._xscale = 30;
                  container._x = posX;
                  container._y = posY+Spc;
      
                  //for the OnRelease function on the thumbnail
                  var BT:MovieClip = tl.attachMovie("Btb", Bt_name, tl.getNextHighestDepth());
                  BT._x = posX;
                  BT._y = posY+Spc;
                  BT.whoIsOn = i;
      
                  BT.onRelease = function() {
                      stopAllSounds();
                      getURL((Modelink+linkTXT[this.whoIsOn]));//this is the link when you click on the thumbnail
                  };
                  BT.onRollOver = function() {
                      _root.Text_Thumbnail(thTxt[this.whoIsOn]);//display the title of the thumbnail by rolling over
                      _root.whoIsOn = this.whoIsOn;
                      _root.bigphotos.loadMovie(thumb[this.whoIsOn],1);//Display the poto of the thumbnail by rolling over
                  };
                  BT.onRollOut = function() {
                      _root.Text_Thumbnail("");
                  };
                  Spc = Spc+160;//for the space betwen the clips            
              }
          };
          //load the xml file selected in the combobox
          trace("the url loaded is: "+theUrl);
          T.load(theUrl);//Load the url selected in the combobox
      }
      
        • 1. Re: how I remove previous MC created with createmovieClip() and attachMovie()
          Ned Murphy Adobe Community Professional & MVP

          You can use the removeMovieClip() function to remove movies added using attachMovie and createEmptyMovieClip.

          1 person found this helpful
          • 2. Re: how I remove previous MC created with createmovieClip() and attachMovie()
            cosmicvibs Level 1

            THanks Ned
            if i want to remove all the clip for example in the movie clip filmstrip i can write _root.filmstrip.removeMovieClip(); ????

            • 3. Re: how I remove previous MC created with createmovieClip() and attachMovie()
              cosmicvibs Level 1

              created a function for remove the movieClips bu it dont wotk :

               

              var link1:Array = new Array();
              var url:String;
              var theUrl:String;
              var whoOn:Number;
              whoOn = 1;

               

               

              //HERE MY FUNCTION
              function reset_all() {
                  _root.filmstrip.removeMovieClip();
              }

              //<---TO HERE

               

               

               

              //load the  xml containing the link for T.Load() function in filmstrip movie clip the xml file
              function loadCat() {
                  var x:XML = new XML();
                  x.ignoreWhite = true;

               

                  x.onLoad = function(success) {
                      var photos:Array = this.firstChild.childNodes;
                      for (i=0; i<photos.length; i++) {
                          link1.push(photos[i].attributes.link1);
                      }
                      url = link1[whoOn];
                      theUrl = url;
                      _root.filmstrip.Tload(theUrl);
                      _root.lengthscroll(theUrl);
                  };
                  x.load("category.xml");
              }
              loadCat();

               

              //create the Listener object
              var cbListener:Object = new Object();
              //create tee change function
              cbListener.change = function(event_obj:Object) {

               

                  if (_root.select.selectedItem.label == "Last updated") {
                      whoOn = 0;
                  } else if (_root.select.selectedItem.label == "Special") {
                      whoOn = 1;
                  }
                  trace(_root.select.selectedItem.label);
                  url = link1[whoOn];
                  trace("url is "+_root.filmstrip.url);
                  theUrl = _root.filmstrip.url;
                  _root.lengthscroll(theUrl);
                  Tload(theUrl);// set the url to load in the T.load() function in filmstrip
              };
              _root.select.addEventListener("change",cbListener);

               

              function Tload(theUrl) {//function that load the url selected in the combobox
                  var T:XML = new XML();
                  T.ignoreWhite = true;
                  var thumb:Array = new Array();//create array
                  var thTxt:Array = new Array();
                  var DescTXT:Array = new Array();
                  var priceTXT:Array = new Array();
                  var linkTXT:Array = new Array();
                  var Modelink = "http://www.windi.no/catalog/advanced_search_result.php?keywords=";//1st part of the link for when you click on the tumbnails
                  var Spc = 0;// space between thumbnail default 0
                  var posX = 0;// thumbnail position x
                  var posY = 0;//thumbnail 1st position y
                  var tl:MovieClip = this;
                  var whoIsOn:Number;
                  whoIsOn = 0;
                  T.onLoad = function(xml) {

               

               

                     reset_all(); /// HERE I APLY IT

               

               

               

               

                      var photos:Array = this.firstChild.childNodes;
                      //loop the php Xml for the thumbnail
                      for (i=0; i<photos.length; i++) {
                          var Num = i+1;
                          var WhoIsOn = Num;
                          var TXTCLIP = "TXTCLIP"+Num;
                          var TXTCLIP2 = "TXTCLIP2"+Num;
                          var TXTCLIP3 = "TXTCLIP3"+Num;
                          var Clp_name = "clip"+Num;
                          var Bt_name = "Bt"+Num;
                          var container = (container+Num);
                          //put each attributs of thumbnail for each photos node
                          thTxt.push(photos[i].attributes.thumbtext);
                          thumb.push(photos[i].attributes.thumbnail);
                          DescTXT.push(photos[i].attributes.thumbdesc);
                          priceTXT.push(photos[i].attributes.thumbprice);
                          linkTXT.push(photos[i].attributes.thumbmodel);
                          _root.Text_Thumbnail(thTxt[whoIsOn]);
                          _root.bigphotos.loadMovie(thumb[whoIsOn],1);
                          var fullink = (Modelink+linkTXT[i]);//the 2nd part of the "Modelink"

               

                          //display Tiles
                          var TXT:MovieClip = tl.attachMovie("TXTCLIP", TXTCLIP, tl.getNextHighestDepth());
                          TXT._x = posX+120;
                          TXT._y = posY+Spc+13;
                          TXT.titleTXT.text = thTxt[i];

               

                          //desccription
                          var TXT2:MovieClip = tl.attachMovie("TXTCLIP2", TXTCLIP2, tl.getNextHighestDepth());
                          TXT2._x = posX+120;
                          TXT2._y = posY+Spc+30;
                          TXT2.titleTXT.text = DescTXT[i];

               

                          // display prices
                          var TXT3:MovieClip = tl.attachMovie("TXTCLIP3", TXTCLIP3, tl.getNextHighestDepth());
                          TXT3._x = posX+120;
                          TXT3._y = posY+Spc+90;
                          TXT3.titleTXT.text = priceTXT[i];

               

                          //display thumbnails
                          var container:MovieClip = tl.createEmptyMovieClip(Clp_name, tl.getNextHighestDepth());
                          container.loadMovie(thumb[i],1);
                          container._yscale = 30;
                          container._xscale = 30;
                          container._x = posX;
                          container._y = posY+Spc;

               

                          //for the OnRelease function on the thumbnail
                          var BT:MovieClip = tl.attachMovie("Btb", Bt_name, tl.getNextHighestDepth());
                          BT._x = posX;
                          BT._y = posY+Spc;
                          BT.whoIsOn = i;

               

                          BT.onRelease = function() {
                              stopAllSounds();
                              getURL((Modelink+linkTXT[this.whoIsOn]));//this is the link when you click on the thumbnail
                          };
                          BT.onRollOver = function() {
                              _root.Text_Thumbnail(thTxt[this.whoIsOn]);//display the title of the thumbnail by rolling over
                              _root.whoIsOn = this.whoIsOn;
                              _root.bigphotos.loadMovie(thumb[this.whoIsOn],1);//Display the poto of the thumbnail by rolling over
                          };
                          BT.onRollOut = function() {
                              _root.Text_Thumbnail("");
                          };
                          Spc = Spc+160;//for the space betwen the clips           
                      }
                  };
                  //load the xml file selected in the combobox
                  trace("the url loaded is: "+theUrl);
                  T.load(theUrl);//Load the url selected in the combobox
              }

              • 4. Re: how I remove previous MC created with createmovieClip() and attachMovie()
                Ned Murphy Adobe Community Professional & MVP

                You should read the Flash help documentation to see how to use the removeMovieClip function, it requires the instance name of the movieclip as an argument.  If that short function you showed at the top is all you did, that will do nothing.  You need to remove each one you create individually, by name.

                 

                Also, because you declare the movieclip variables inside that function. they do not have scope outside of that function, so you should declare the variables outside to have more global access to manip[ulating them.

                1 person found this helpful
                • 5. Re: how I remove previous MC created with createmovieClip() and attachMovie()
                  cosmicvibs Level 1

                  Thanks and sorry again, I change the function  with this :

                   

                  function reset_all() {
                      for (i=0; i<100; i++) {
                          Num = i+1;
                          var TXTCLIP = "TXTCLIP"+Num;
                          var TXTCLIP2 = "TXTCLIP2"+Num;
                          var TXTCLIP3 = "TXTCLIP3"+Num;
                          var Clp_name = "clip"+Num;
                          var Bt_name = "Bt"+Num;
                          _root.filmstrip.removeMovieClip(TXTCLIP,1);
                          _root.filmstrip.removeMovieClip(TXTCLIP2,1);
                          _root.filmstrip.removeMovieClip(TXTCLIP3,1);
                          _root.filmstrip.removeMovieClip(Clp_name,1);
                          _root.filmstrip.removeMovieClip(Bt_name,1);
                      }
                  }

                   

                  i call the function at the same place, but nothing happen????

                  • 6. Re: how I remove previous MC created with createmovieClip() and attachMovie()
                    cosmicvibs Level 1

                    THANKS YOU VERY VERY MUCH...Ned!!!

                    now it works

                     

                    function reset_all() {
                        for (i=0; i<100; i++) {
                            Num = i+1;
                            var TXTCLIP = "TXTCLIP"+Num;
                            var TXTCLIP2 = "TXTCLIP2"+Num;
                            var TXTCLIP3 = "TXTCLIP3"+Num;
                            var Clp_name = "clip"+Num;
                            var Bt_name = "Bt"+Num;
                            removeMovieClip(TXTCLIP);
                            removeMovieClip(TXTCLIP2);
                            removeMovieClip(TXTCLIP3);
                            removeMovieClip(Clp_name);
                            removeMovieClip(Bt_name);
                        }
                    }