4 Replies Latest reply on May 20, 2014 8:36 AM by resdesign

    call all instances of a symbol

    MacBookPro_d_1

      Hej,

       

      i need to place 10 different kinds of symbols, a hundred times each on my stage. Theses symbols have the same shape, but different colors. I need to filter them out in a tiny top-menu.

      So, if i click e.g. on a red circle, i want all non red symbols to set there opacity to 0.5.

      It could be simple if i place all red symbols into a container "$color-symbols" and set the opacity to them. But that is not possible, because I need to place each symbol manually. And if they are childs of another symbol, drag and drop is horrible.

      Now i am wondering if it is possible to call all symbols on stage that are instances of a symbol in my library.

       

      And is there a nice way to call "all-other-colors" instead of

       

      sym.$("color-1").animate({opacity:0.5},500);

      […]

      sym.$("color-9").animate({opacity:0.5},500);

      sym.$("my-own-color").animate({opacity:1},500);

       

      on every button on stage?

        • 1. Re: call all instances of a symbol
          resdesign Adobe Community Professional & MVP

          You can give them a class and use a for loop

          for example

          supposing your elements are incrementing element0, element1, etc/ ortherwise make an array with their names and use the array in the names  var elements = ['name', mane2','othername'];   use  sym.$(elements[i]) below.

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

          sym.$('element'+i).addClass('stuff"+i);

          sym.$(".stuff"+i).css({background-color":"red"});

          }

          1 person found this helpful
          • 2. Re: call all instances of a symbol
            MacBookPro_d_1 Level 1

            Thanks for your help,

             

            i use the classes to specify a target url for each symbol.

            For Example:

            I have three red symbols and three blue symbols.

            The classes for the red-ones are:

            33451, 56789 and 45678

            for the blue ones:

            983, 4, 1002

             

            Inside of my symbols i have a script:

             

            var names = (e.target.id).split("_");

            var page = names[2];

            var link = "http://www.url.no/subpage/"+page;

            window.open(link, "_self");

             

            If i find another way to put a specific ID (and it must be a number) on to each Instance, i could use the way you describe.

             

            Because your idea is to use the class-names, there is no way to call all instances of a given symbol?

             

            Is it possible to use wildcards for my array?

            So i could name them "red-33451#1", "red-56789#2", "red-45678#3". And cut out everything between "-" and "#".

            But remember that i need to place a few hundreds of them, which isn't fun. And if i need to insert one later or if i delete another one, i need to verify all my functions.

            • 3. Re: call all instances of a symbol
              MacBookPro_d_1 Level 1

              What if i have a function inside of each symbol ("want-be-seen").

              Is ist possible to fire a global trigger, that starts this function, wherever it will be?

              • 4. Re: call all instances of a symbol
                resdesign Adobe Community Professional & MVP

                Well, if you want to use a global function that might work but I am not sure. You can test it I guess. Also, you can have several classes on elements separated by a space. So I imagine you could still use a class do do what you want.

                1 person found this helpful