3 Replies Latest reply on Jun 19, 2013 3:48 PM by jbowden

    Why does this code not work on document.compositionReady

    Marlene Level 1

      I have a symbol called printMenu.

      Inside printMenu I have 5 text elements.

       

      The following code reports I have 0 elements in the printMenuChildren variable when it should be 5. Not sure why.

      var printMenuChildren = sym.getSymbol("printMenu").getChildSymbols();

      alert(printMenuChildren.length);

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

                          alert (printMenuChildren[i]);

      }

        • 1. Re: Why does this code not work on document.compositionReady
          Endoplasmic Level 2

          This was a super pain point for me, so I know your fustration.

           

          The problem is that creationComplete is fired before compositionReady (which is dumb).

           

          What I ended up doing was making each symbol have an "onInit" method that I called from my main compositionReady call like so:

           

          //loop through things that need to do things

          var elements = sym.getChildSymbols();

          var total = elements.length;

          var i = 0;

          for(i = 0; i < total; i++){

            if(typeof elements[i].onInit == 'function'){

              elements[i].onInit();

            }

          }

           

          edit: This was in Edge 1.0 and 1.5, this may have been fixed in CC

          • 2. Re: Why does this code not work on document.compositionReady
            jbowden Adobe Employee

            Hi Marlene,

             

            Your code actually works for me when I try it in the composiitionReady event.

             

            Are you certain that your printMenu symbol actually contains 5 symbol instances?

             

            hth,

            Joe

            • 3. Re: Why does this code not work on document.compositionReady
              jbowden Adobe Employee

              Oh wait - after rereading your post, you did mention there were five text elements in the symbol. I'm afraid getChildSymbols won't work for that - it only gets the symbol instances within a symbol.

               

              Instead, use jQuery's children() method to get the child elements of the div (symbol instance). Like so:

               

              var printMenuChildren = sym.$("printMenu").children();

              alert(printMenuChildren.length);

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

                                  alert (printMenuChildren[i]);

              }

               

              And it will work just fine in the compositionReady handler.

               

              hth,

              Joe