6 Replies Latest reply on Mar 25, 2014 5:10 PM by DesignByte

    createChildSymbol

    DesignByte

      Hi,

       

      I need help to test if the element intel1 contains no child symbols,otherwise i need to delete it before i create a new child.

       

      Thanks!

       

      if(sym.$("intel1").length==0){

           sym.createChildSymbol("server", "intel1");

      }else{

           sym.getSymbol("intel1").getSymbol("server").deleteSymbol();

           sym.createChildSymbol("server", "intel1");

      };

        • 1. Re: createChildSymbol
          Sudeshnasarkar27 Adobe Employee

          Hi ,

           

          You can try it this way -

           

          var childSymbols = sym.getSymbol("intel1").getChildSymbols();

          console.log(childSymbols);

          if(childSymbols.length == 0)

          {

                    console.log("createChildSymbol created started");

                    var m_item = sym.createChildSymbol("server", "intel1");

          }

          else

          {

                    console.log("Delete and Create started"); 

                    var child = sym.getSymbol("intel1").getChildSymbols();

                    console.log(child);

                    child[0].deleteSymbol();

                    console.log("deleted");

             var s = sym.createChildSymbol("server", "intel1");

             console.log("created again");

          }

           

          Attached a simple sample to show the behavior.

           

          Thanks and Regards,

          Sudeshna Sarkar

          1 person found this helpful
          • 2. Re: createChildSymbol
            DesignByte Level 1

            Thanks for helping Sudeshna.For some reason the else statement doesn't take effect childSymbols.length is always 0. Sorry, I'm new to edge animate...

            ==================================================================================

             

            function loadServer(server,container){

            var childSymbols = sym.getSymbol(container).getChildSymbols();

            console.log(childSymbols.length);

             

            if(childSymbols.length == 0){

                      console.log("createChildSymbol created started");

                      var m_item = sym.createChildSymbol(server, container);

                      console.log(childSymbols.length); //<--- this remains 0 after child was created so else statement never run

              } else{

                      console.log("Delete and Create started"); 

                      var child = sym.getSymbol(container).getChildSymbols();

                      console.log(child);

                      child[0].deleteSymbol();

                      console.log("deleted");

                var s = sym.createChildSymbol(server, container);

                console.log("created again");

              };

             

            };

            • 3. Re: createChildSymbol
              DesignByte Level 1

              Help please, I am really stuck here.

              • 4. Re: createChildSymbol
                Sudeshnasarkar27 Adobe Employee

                Yes , you are right. I can see the new child added to the symbol but the "childSymbols.length" remains 0. Let me check what is going wrong.

                 

                Regards,

                Sudeshna

                • 5. Re: createChildSymbol
                  Sudeshnasarkar27 Adobe Employee

                  Hi ,

                   

                  getChildSymbols() only work on stage or composition level.

                   

                  Try it this way -

                   

                  var symbolChildren = sym.$("intel1").children();

                  var childrenBefore = symbolChildren.length -1 ;

                  console.log("Before : " + childrenBefore);

                  var m_item = sym.createChildSymbol("server", "intel1");

                  var symbolChildren = sym.$("intel1").children();

                  var childrenAfter = symbolChildren.length -1;

                  console.log("After : " + childrenAfter);

                   

                   

                  Thanks and Regards,

                  Sudeshna Sarkar

                  • 6. Re: createChildSymbol
                    DesignByte Level 1

                    Hi Sudeshna,

                     

                    Thanks for helping me out! Much appreciated

                     

                    Richard