2 Replies Latest reply on Mar 21, 2011 1:54 AM by Ibarim

    remove from stage objects storaged in array

    Ibarim Level 1



      I got an array of objects:


      for (i=0;i<7;i++) {
            ar.push(canObj = new canvasObject());


      Then I add these objects to stage by calling a function inside every object - that function returns 'this' :


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


      inside canvasObject:


      public function returnThis():void {
           return this;    


      Then I try to remove these objects form stage like this:


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



      And the problem is that these canvasObjects still stay on the stage. I checked list of main component's children and found out that every canvasObject is actually removed form children list during the loop, but finally, when loop ends the display list again contains these objects.


      private function newFunction():void {
      for (i=0;i<ar.length;i++) {
       list = getChildren();      //during 1st iteration I see all 7 children and every next iteration reduce number by 1 as I expect
       removeChild(ar[i]);      //one of the children is removed
       list = getChildren();     //during 1st iteration I see 6 children left and every next iteration reduce number by 1 as I expect


      When loop ends I press 'resume' button during debug mode and flex does something strange which makes all the children come back on the stage (and children list).

      Any idea what am I doing wrong?