3 Replies Latest reply on Nov 13, 2013 4:22 AM by elainecc

    Problems with click event

    RedKezia

      When I try to add a click event on a symbol, I can't access to the symbol, only to the parent. For example, if on the event click on a specific symbol A I add the code

      var symbolElement = sym.getSymbolElement();

      symbolElement.hide();

       

      It will hide the parent of A, instead of hiding A. How do I access to A?

        • 1. Re: Problems with click event
          elainecc Adobe Employee

          Hi, RedKezia-

           

          What's happening here is that sym refers to the current symbol context.  When you add an event on a symbol instance on the main timeline, sym refers to the Stage.  In order to hide the element, you'll need to do this:

           

          var symbolElement = sym.getSymbol("A").getSymbolElement();

          symbolElement.hide();

           

          Comparable to this is:

          var symbolElement = sym.$("A");

          symbolElement.hide();

           

          Also, this does the same thing:

          sym.$("A").hide();

           

          Hope that helps!

           

          Thanks,

           

          -Elaine

          1 person found this helpful
          • 2. Re: Problems with click event
            RedKezia Level 1

            Hi Elaine, thanks a lot for the reply. I wasn't clear in my question. I am working on a strategy game. I have a map symbol with 20 bases symbols inside the map. When I click on a base, I would like to get the ID of that base. So my idea is to instance the 20 bases and saving an ID variable inside each base, so then I can put some generic code inside the symbol click action, like getVariable("ID"). But I guess what I can do is create another symbol inside the base, and add the action click inside that symbol, so when I access to sym, It will get the base. Thanks again!

            • 3. Re: Problems with click event
              elainecc Adobe Employee

              Hey, RedKezia-

               

              So what you can do is put the click event within the symbol, and then set the id variable in the initialization function (e.g. creationComplete).  For a sample of how you might want to handle this, check out the Floral Match Maker sample that we have up:

               

              http://www.adobe.com/devnet/edge-animate/articles/showcase-sample-files.html

               

              Specifically, look at the gameBoard and its pieces; the pieces know what color they are for comparison purposes.

               

              -Elaine

              1 person found this helpful