5 Replies Latest reply on Oct 7, 2013 12:13 PM by resdesign

    addressing dynamically created symbols

    juicy_life Level 1

      I'm not sure what's the best way to address a specific dinamically created symbol because I don't see in Edge's API any way to get the symbol's instance name. The .getSymbol() method would be the easiest way to do it, but it takes the symbol "instance" name and I don't know which one it is. When I use .createChildSymbol() I just pass the symbol "type" name and the parent element name to be put inside but nothing about the symbol instance name that's been created. The .getChildSymbols() method doesn't help much because it retrieves "all" direct children instances found, and I have more than one and of different types.

       

      I need to get one specific symbol among several I created dinamcally, so how should I do it best?

       

      I'm thinking about using .getChildSymbols() and loop through them all, get the DOM of each symbol with .getSymbolElement(), then use the "class" attribute to at least identify the different types of children symbols retrieved. I now have a subset of children-brothers (symbols of the same type = class) and I can walk through them. At this point, my only hope to distiguish them is the z-index parameter I passed when I created the symbols using .createChildSymbol().

       

      One other option would be to "save" the returned handler to each symbol created with .createChildSymbol() in an object like this { symbol: handler, name: "any name", created: "date/time", ... } and save them in an array of objects.

       

      Any better ideas?

        • 1. Re: addressing dinamically created symbols
          juicy_life Level 1

          I've found something in http://www.edgedocks.com/edgecommons#anchor_edgecommons_21. This guy has made a getSymbolName function which is exactly what we need to solve this problem.

          • 2. Re: addressing dinamically created symbols
            AMULI Level 4

            Hi juicy_life,

             

            Thank you for pointing to this EC function.

             

            But I persist in not completely understanding your very interesting question Could you explain (may be give an example) why you need that kind of access by instance name ?

             

            All that came to my mind since you have initiated that thread is to either use

             

            1) a variable pointing to that particular instance : when you are at instantiating it, instead of giving it a name, isn't it simpler to store it in a global variable ?

             

            or 2) an array of all instances, but we still need a variable to store the index of the particular instance.

             

            What bothers me in the three tracks you've considered

             

            3) "tagging" the instance by giving it a proper class

             

            4) array of objects having a name property

             

            is that in both cases you need a traversal to recover the instance : in 3) the traversal is hidden under a jQuery selector (or a find()) ; in 4) you need to explicitly traverse the array via a for loop (or each()).

             

            This contrasts with a variable that will give you access to the instance without the need of a traversal. But surely I miss something

             

            Gil

             

            PS : with the EC function getSymbolName(), it seems that we also need a traversal.

            • 3. Re: addressing dinamically created symbols
              juicy_life Level 1

              Gil, I agree with all you said. I ended up using 2) to manage my situation. 3) & 4) add too much complexity and 1) too many variables. I don't like to use global variables, so when I need to use a variable everywhere, I prefer to store it into a symbol variable instance that I know will persist (the stage, maybe) and recover it when I need it.

               

              The true reason I asked for the "name" function, was more a matter of consistency within the Edge API than a no-way-out problem. It's just annoying you can get a symbol manually added to your edge animation by its "name" using .getSymbol(), but there is not an easy way to use that function with a dinamically created symbol cause edge doesn't "give" you names when you create symbols dinamically. Edge must assign a name to any dinamically created symbol but, which one?

               

              I just want to use .getSymbol() for both, manually and dinamically created symbols. I used Chrome code inspector to see the structure of a symbol object, and found the "name" (or ID) assigned by Edge to a dinamically created symbol...

               

              mySym.aSymbolInstances will give you an array with all "names" when you create symbols with .createChildSymbol(). If you just created one symbol, then mySym.aSymbolInstances[0] will return its "name" (ID), something like this: #eid_1379485757227_mySymType

              • 4. Re: addressing dinamically created symbols
                AMULI Level 4

                Hi juicy_life,

                store it into a symbol variable instance that I know will persist (the stage, maybe)

                 

                Looks like a global variable

                 

                It's just annoying you can get a symbol manually added to your edge animation by its "name" using .getSymbol(), but there is not an easy way to use that function with a dinamically created symbol

                 

                May be are you also an AS3 coder used to search through the display list accessing display objetc containers either by index (getChildAt()) or by name (getChildByName()).

                mySym.aSymbolInstances will give you an array with all "names" when you create symbols with .createChildSymbol().

                 

                Thank you for this helpful information. I didn't know about it.

                "name" (ID), something like this: #eid_1379485757227_mySymType

                 

                For a manually instantiated symbol symB, nested in symA, itself instantiated in the Stage Symbol, the fully qualified name (ID) is Stage_symA_symB.

                 

                It's useful to write a global function for the behavior (on click for example) shared by a group of buttons, provided you adopt a naming convention btn1, btn2, etc. Passing the event objet to that function, you can then recover the number of the clicked button via

                 

                evt.target.getAttribute("ID").substr()

                 

                This abstraction avoids duplicating the same code (differing only by the button number) on each button.

                 

                Gil

                • 5. Re: addressing dinamically created symbols
                  resdesign Adobe Community Professional & MVP

                  Why not give an id to your created symbols?