0 Replies Latest reply on Feb 4, 2010 4:47 PM by windsurf88

    How to clear a Sprite? not referencing all the children correctly?

    windsurf88 Level 1

      Here is my function -- trying to remove all the children in the sprite whichPage... hmmm.  Do you see how to remove the childrens?

      function onResult2dArray(thisArray:Array):void {
          pageArray=thisArray;
          //whichPage.graphics.clear();
          trace(whichPage.numChildren);  // whichPage has a lot of children!


          if (currentPage > 1) {
              for (i=0; i<=whichPage.numChildren; ++i) {
                  whichPage.removeChildAt(i);
              }
          }

          var arrayOfWordBoxes:Array = new Array();


          for (var i:uint = 0; i<pageArray.length; i++) {
              var littleSquare:Sprite = new Sprite();

              whichPage.addChildAt(littleSquare, 0);
              arrayOfWordBoxes.push(littleSquare);

              createRect(littleSquare,0,0,pageArray[i]["width"], pageArray[i]["height"],0x550000);

              littleSquare.x = pageArray[i]["x"];
              littleSquare.y = pageArray[i]["y"];

              arrayOfWordBoxes[i].addEventListener(MouseEvent.MOUSE_OVER, movePageHere);//new line
          }

          addChildAt(whichPage, 100);
          whichPage.x = 250;
          whichPage.y = 0;
          //x=250; location for left side of page
          //y=0;


          function movePageHere(e:MouseEvent):void {//new function
                  AdoptWindow.x=-800;
                  AdoptWindow.y=700;

          }

          function createRect(rect:Sprite,x:Number,y:Number,width:Number,height:Number,color:Numbe r):void {
              rect.graphics.beginFill(color);
              rect.graphics.drawRect(x, y, width, height);
              rect.graphics.endFill();
          }
      }