1 Reply Latest reply on May 26, 2014 12:53 AM by NicoM

    [AfterEffects CS6] : Crash when removing a child control

    NicoM

      Hello,

       

      I work in a script for AfterEffect (JSX).

      In certain situations I remove controls from a panel, it usualy works.


      But sometime, this code crashes (inside 'remove'):

      childCheckbox = myPanel.children[0];

      myPanel.remove(childCheckbox);


      According to the object browser:

      myPanel is a 'Panel' object

      childCheckbox is a 'Checkbox' object.


      I can read this message:

      Bad argument Function {LiveObject("Panel").property('find')} is undefined


      Does anybody could explain that to me ?

      What's wrong ?


      Thanks


      Nico

        • 1. Re: [AfterEffects CS6] : Crash when removing a child control
          NicoM Level 1

          Hello,

           

          I get the same behavior inside 'for' loop.

           

          I try to use a temporary array in order to list all controls to remove

           

          Code sample:

          var children = parent.children;

          var childrenToRemove           = [];

           

           

          for (var index = 0; index < children.length; index++) {

            var child = children[index];

           

           

            if (child != childToPreserve && isUIControl(child)) {

              childrenToRemove.push(child);

            }

          }

           

           

          // Remove controls in the reverse order.

          childrenToRemove.reverse();

           

           

          for (var index in childrenToRemove) {

            var controlToDelete = childrenToRemove[index];

            // 'index' is invalid here, it references 'indexOf'

            ...

           

          Is there anybody who has an idea ?

           

          Thanks

           

          Nico