2 Replies Latest reply on Nov 18, 2009 9:31 AM by manofspirit

    removeChildAt with removedEffect causing problem

    manofspirit Level 1

      Hi

      My application removes CHOSEN children in a container using a loop.

      my application crashes if removedEffect is enable in children.

       

      Here is the code for removing

       

      var numberOfChildren:Number = nodesArea.numChildren;
      
      for(var i:Number = (numberOfChildren-1) ; i >= 0; i--){
           if((nodesArea.getChildAt(i) as Node).isGud == true){
                nodesArea.removeChildAt(i);
           }
           
      }
      

       

       

       

      Please download and test the sample application yourself to experience the problem.

       

      Thanks

        • 1. Re: removeChildAt with removedEffect causing problem
          RK...

          Hi,

          There is a synchronization issue that occurs while the removedEffect is playing. So I've slightly modified your code. Added hideEffect instead of removedEffect. In main application a timer is added to remove the invisible nodes. Hope this will help you

           

          Node.mxml

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Canvas moveEffect="Move" showEffect="Fade" hideEffect="Fade" xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="100" backgroundColor="#B6A3FF">

          <mx:Script>

          <![CDATA[

           

          public var isGud:Boolean = true;

           

          ]]>

          </mx:Script>

          </mx:Canvas>

           

           

          RemoveChildProblem.mxml

           

          private var _timer: Timer = null;

          private function removeChildren():void{

          var numberOfChildren:Number = nodesArea.numChildren;

           

          if (!_timer) {

          _timer = new Timer(550);

          //Add listener to update progress bar

                      _timer.addEventListener(TimerEvent.TIMER, removeHandler, false, 0, true);

          }

                      //Start timer

                      _timer.start();

                     

          for(var i:Number = (numberOfChildren-1) ; i >= 0; i--){

          if((nodesArea.getChildAt(i) as Node).isGud){

          (nodesArea.getChildAt(i) as Node).visible = false;

          }

          }

           

          }

           

          private function removeHandler(event: TimerEvent): void {

          var numberOfChildren:Number = nodesArea.numChildren;

          for(var i:Number = (numberOfChildren-1) ; i >= 0; i--){

          if(!(nodesArea.getChildAt(i) as Node).visible){

          nodesArea.removeChildAt(i);

          }

          }

          _timer.stop();

          }