3 Replies Latest reply on Jan 23, 2014 9:05 AM by celine of alchimia

    How to discard a random symbol

    celine of alchimia

      Hello,

      I have a problem:  I have a keyframe where I must to upload a random series of symbols, and I do it with the script:

       

      var myVar = Math.floor((Math.random()*6)+1);

       

           var stage = sym.$("Stage");

       

                 var myAni = sym.createChildSymbol("Symbol_" + myVar, "stage");

       

                myAni.appendTo(stage);

       

       

      The script works fine, but, at NEXT keyframe I must load another series. The problem is that the symbol loaded in the previous keyframe is still present and the new symbol overlaps it.

       

      How can I unload or discard the previous symbol?

       

      Thanks in advance.

      Celine

        • 1. Re: How to discard a random symbol
          Saurav Adobe Employee

          Hi Celine ,

           

          Can you just try by listing all the child symbols using sym.getChildSymbols() and then deleting them using sym.deleteSymbol() . I assumed that you want to add different set of symbols at a different time on the timeline .

           

          Thanks

          Saurav

          1 person found this helpful
          • 2. Re: How to discard a random symbol
            heathrowe Most Valuable Participant

            Another option is to set the symbol instance to an element container (draw out a rectangle element), instead of placing them on the Stage.

             

            So, changes in bold

             

            var myVar = Math.floor((Math.random()*6)+1);

            // Set the child symbol container to an element; in my case a Rectangle element called Rectangle.

                var stage = sym.$("Rectangle");

            // Then before the symbol instance is created, call the empty() method on the previous container. In other

            // words make sure it is empty before adding a random one.    

                stage.empty();

                var myAni = sym.createChildSymbol("Symbol_" + myVar, stage);

                myAni.appendTo(stage);

             

            Darrell

            • 3. Re: How to discard a random symbol
              celine of alchimia Level 1

              Both suggestions work! Thanks for solving the problem.

               

              celine