5 Replies Latest reply on Jul 7, 2014 10:23 AM by jbowden

    Referencing symbols from symbol elements

    Tim. Signore Level 1

      Hello,

      What is the correct syntax to reference a symbol ( in order to control its timeline) from a symbol element, when this is returned as the event target. I don't want to hard code this/ use symbol names, just step back from the currently targeted symbol element to reference the symbol that owns it.

      many thanks for any help.

        • 1. Re: Referencing symbols from symbol elements
          Tim. Signore Level 1

          Sorry, to be clear, I mean the symbol element as in getSymbolElement(), not an element within the symbol.

          • 2. Re: Referencing symbols from symbol elements
            Tim. Signore Level 1

            In case this helps anyone else, I finally achieved what i outlined above using the code below. The stage holds a symbol called allButtons, which holds two symbols, Button1 and Button2. The symbol elements of these are the click targets, and have the class btnClicka.

             

            $(".btnClicka").on("click", function(e){

              var targetID = e.currentTarget.id;

              var buttonClicked = targetID.charAt(targetID.length-1);

              console.log("click " + buttonClicked);

              sym.getComposition().getStage().getSymbol("allButtons").getSymbol("Button" +buttonClicked).stop("Touch");

             

            });


            To me, this does not seem like an elegant solution; is it necessary to go all the way out to the stage and back in again to target what I want, when it's only one step away from where I started. Seems like walking round the block to visit the house next door. If anyone knows the shorter/ clever way to do this, I would love to know.

            • 3. Re: Re: Referencing symbols from symbol elements
              jbowden Adobe Employee

              Hi Tim,

               

              Instead of this:

              sym.getComposition().getStage().getSymbol("allButtons").getSymbol("Button" +buttonClicked).stop("Touch");

               

              Try this:

              sym.getParentSymbol().getSymbol("Button" +buttonClicked).stop("Touch");

               

              Or even easier (if your button will always be in the symbol that you want to control):

              sym.stop("Touch")

               

              For more info:

              Adobe Edge Animate CC JavaScript API

               

              hth,

              Joe

              1 person found this helpful
              • 4. Re: Referencing symbols from symbol elements
                Tim. Signore Level 1

                Hi Joe,

                Many thanks for your reply. I have tried both of the approaches you suggested; the first gives me this error:

                 

                Uncaught TypeError: Cannot read property 'getSymbol' of null

                 

                The second throws no error, but there is no change(in other words the stop("Touch") command is not executed.

                 

                I have put my test files (very simple) here:

                ButtonsTest.zip - Box

                Would appreciate any light you can throw.

                Thanks again,

                Tim

                 


                • 5. Re: Re: Referencing symbols from symbol elements
                  jbowden Adobe Employee

                  Sorry, my first reply was outside the scope of the code in compositionReady handler (didn't notice this until I downloaded your file). In this scope, this line (less code) should work:

                   

                  sym.getSymbol("allButtons").getSymbol("Button" +buttonClicked).stop("Touch");

                   

                  This works because the scope is already Stage, so you only need to getSymboll rather than getting the Stage first.

                  1 person found this helpful