6 Replies Latest reply on Feb 10, 2014 7:20 AM by resdesign

    Get the ID of a dynamically created symbol from library, INSIDE another symbol.

    lester_dm Level 1

      Hi everyone,

       

      I'm trying to get the id from a dynamic created symbol from library.

      When dynamically creating the symbol directly on the stage (or composition level), there's no problem.

      But I just can't get it to work when creating the symbol inside another symbol. 

       

      Below some examples using both "getChildSymbols()" and "aSymbolInstances" 

       

      // USING "getChildSymbols()" ///////////////////////////////////////////////////////////////////////// 

      // ON THE STAGE 

      var m_item = sym.createChildSymbol("m_item","Stage");

      var symbolChildren = sym.getChildSymbols(); 

      console.log(symbolChildren[0].getSymbolElement().attr('id')); // ok eid_1391853893203

       

      // INSIDE ANOTHER SYMBOL

      var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement()); 

      var symbolChildren = sym.getSymbol("holder").getChildSymbols(); // Am i using this wrong maybe?

      console.log(symbolChildren.length) // returns 0 so can't get no ID either

       

      // USING "aSymbolInstances"" ////////////////////////////////////////////////////////////////////////// 

      // ON THE STAGE

      var m_item = sym.createChildSymbol("m_item","Stage"); 

      console.log(sym.aSymbolInstances[0]); // ok (i guess) x.fn.x.init[1] 0: div#eid_1391854141436

       

      // INSIDE ANOTHER SYMBOL

      var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement());

      console.log(sym.getSymbol("holder").aSymbolInstances[0]); // Javascript error in event handler! Event Type = element 

       

      In this post http://forums.adobe.com/message/5691824 is written: "mySym.aSymbolInstances will give you an array with all "names" when you create symbols"

      Could it be this only works on the stage/ composition level only and not inside a symbol? 

       

      The following methods to achieve the same are indeed possible, but i simply DON'T want to use them in this case:

      1) Storing a reference of the created symbol in an array and call it later by index.

      2) Giving the items an ID manually on creation and use document.getElementById() afterwards.

       

      I can't believe this isn't possible. I am probably missing something here.

      Forgive me I am a newbie using Adobe Edge!
      I really hope someone can help me out here.

       

      Anyway, thnx in advance people!

      Kind Regards,

      Lester.

        • 1. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
          resdesign Adobe Community Professional & MVP

          You need  to add the id in code to access your created symbols as below(do not forget the # when you use the id after). You can also add a class. Courtesy to me from Zaxist a few months ago.

           

          var NewSymbolInstance = sym.createChildSymbol("mySymbol", "Stage");

          NewSymbolInstance.element.addClass("classNamehere");

          NewSymbolInstance.element.attr("id","newIdNamehere");

           

          and use is like this for example:

           

          sym.getSymbol("#newIdNamehere").$("Text").html("text here");

          1 person found this helpful
          • 2. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
            lester_dm Level 1

            Hi,

             

            Thanks for the quick response!

            True this is also a possibility. But this method is almost the same of "Giving the items an ID manually on creation and use document.getElementById() afterwards".

            In this way (correct me if i'm wrong) you have to give it an unique ID yourself. In a (very) big project this isn't the most practical way.

            Although I know it is possible.

             

            Now when Edge creates a symbol dynamically on the Stage (or composition level) or inside another symbol it always gives the symbol an ID like "eid_1391853893203".

            I want to reuse this (unique) ID given by Edge after creation.

             

            If created on the stage directly you can get this ID very easy. Like this;

             

            var m_item = sym.createChildSymbol("m_item","Stage");

            var symbolChildren = sym.getChildSymbols(); 

            console.log(symbolChildren[0].getSymbolElement().attr('id')); // ok eid_1391853893203

             

            I want to do exactly the same when created INSIDE another symbol.

             

            var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement());

             

            Now how can I accomplish this? How can I get the Id of a dynamically created symbol INSIDE another symbol instead of created directly on the stage?

            This is what i'm after.

             

            Thnx in advance!

            • 3. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
              resdesign Adobe Community Professional & MVP

              Frankly I do not see the advantage. I created a sample for you where I use the created id in symbol and nested symbols which gives me control of the symbols.

              https://app.box.com/s/i2x8lhbz33asdgguk6e9

              1 person found this helpful
              • 4. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
                lester_dm Level 1

                Hi again,

                 

                Thanks for taking the time to set up an example for me. I really appreciate this!

                I have set up another example based on yours to try to explain what I mean exactly.

                 

                https://app.box.com/s/dw6a1klvr4zfoqn66kl6

                 

                Take the scenario were you would have a very complex website with a lot of dynamically created and nested symbols.

                You would always have to give your items a unique ID yourself. And you have to make sure there won't be any conflicts on ID's.

                 

                Now Edge already gives each dynamically created symbol a unique ID. Why give it another one?

                If we can use this unique ID (made by Edge) we can't make any mistakes on our self-given ID's and we save time also.

                I see this as an advantage.

                 

                My problem is I don't know HOW I can retrieve that ID from a symbol inside another symbol as mentioned above.

                Getting that ID from a symbol on the stage is no problem. Can't this be done?

                 

                Thnx again!

                • 5. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
                  lester_dm Level 1

                  Ok, I solved my own problem by using the (simple) code below.
                  I suppose "getChildSymbols()" and "aSymbolInstances" only work on stage/ composition level.

                  Just thought I'd share this to everyone. Peace!

                   

                  var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement()); 

                  $.each(sym.$("holder").children(), function(index, obj) { 

                      console.log($(sym.$("holder").children()[index]).attr('id'));

                  });

                  • 6. Re: Get the ID of a dynamically created symbol from library, INSIDE another symbol.
                    resdesign Adobe Community Professional & MVP

                    Sorry I was out yesterday. So glad you found the solution! Good luck on your project.