3 Replies Latest reply on Mar 10, 2009 8:37 PM by Arkabyt

    Removing movieclips created at runtime

    Arkabyt
      I'm trying to remove movieclips created at run time using "createEmptyMovieClip" but I'm having a problem calling the "removeMovieClip" function. The difficulty seems to be that the string that I assign as the instance name of the new movie clip doesn't actually refer to the created clip when I try to call "removeMovieClip".

      So the "removeMovieClip" function doesn't work if the target name is pulled from the array. My guess is that this has something to do with the values of the array being strings...and it does when when I manually type Apple.removeMovieClip(); in because Apple is the movieclip object name. How do call the "removeMovieClip" function using a var as the target?



        • 1. Removing movieclips created at runtime
          Ned Murphy Adobe Community Professional & MVP
          Since myArray is an array of strings, then you need to use the bracket notation to interpret/target them as objects.

          this[myArray[ i]].removeMovieClip();
          • 2. Re: Removing movieclips created at runtime
            Level 7
            You could do as NedWebs suggested or you could store the references you
            create, and then remove those - something like:

            //code used to create movie clip
            var yPos:Number = 50;
            var myArray = new Array();
            var myRefs = new Array(); //NEW
            myArray[0] = "Apple";
            myArray[1] = "Orange";
            myArray[2] = "Grape";


            for (i = 0; i < myArray.length; i++) {

            var myClip = this.createEmptyMovieClip(myArray ,
            this.getNextHighestDepth());
            var apgList:TextField = myClip.createTextField("apgList", 1, 0, 0, 150,
            20);
            apgList.text = myArray
            ;
            apgList.border = true;
            apgList.background = true;
            apgList.backgroundColor = 0xFFFFFF;
            var jj:Number = j + 5;
            myClip._x = 400;
            myClip._y = yPos;
            yPos = yPos + 25;

            myRefs.push(myClip); //NEW - store a reference to the actual clip
            }

            //code used to remove movie clip

            for (i = 0; i < myRefs.length; i++) {

            myRefs .removeMovieClip(); //NEW - SHOULD WORK
            //Apple.removeMovieClip(); //... BUT WHY MANUAL INSTEAD OF STRING -
            because Apple is a MovieClip, not a String
            }
            stop();


            --
            Dave -
            www.offroadfire.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: Removing movieclips created at runtime
              Arkabyt Level 1
              All those calls to removeMovieClip worked once my real issue was solved. The problem was the variable used as the instance name of my newly created movie clip was pulled from an XML node. No matter what call I made to removeMovieClip it failed to work UNTIL I changed the variable pulled from the XML to a string using:

              var emailClipName:String = Matrix[actPath].emails .itemID;

              once converted into a string and put into an array the call removeMovieClip(myClips[j]); worked!

              My best guess is that the original variable declaration was of a different type than :string...maybe :object since it was pulled from a :XMLNode.