3 Replies Latest reply on Mar 12, 2015 3:15 PM by Zoze

    dynamic button change color on click and reset the unclicked buttons

    Zoze Level 1

      Hi,

       

      I have have 3 buttons created dynamically from JSON file.

       

      When I click on any of them the color is changed to red. (this is good).

      But when I am going to click another button the previous red that I have clicked earlier doesn't change to it's grey statement, except from the last button which is the only one that works (is changing between red and grey).

       

      If for the JSON make variable for the index e.g.(0,1,2) is working, but I want to make it work without index it. I want to make it with symbol's attr.


       

       

      here is the files if someone can give it a try.

       

      Dropbox - hover.rar

        • 1. Re: dynamic button change color on click and reset the unclicked buttons
          Zoze Level 1

          in composition ready I have:

           

          sym.hovergrey = function () {

            stage.getSymbol(".doorC").$("hover").css({

            'background-color':'#c0c0c0'});

          }

           

          but when i run the function hovergrey on click event doesn't return all the elements that hasClass .doorC to grey. It returns just the last one which is the last from JSON's index.

           

          why ?

          • 2. Re: dynamic button change color on click and reset the unclicked buttons
            resdesign Adobe Community Professional & MVP

            I would do this assuming that the change occurs on mouse over the symbol doorC.

             

            sym.$(".doorC").bind('mouseenter', function(){

                 sym.getSymbol(".doorC").$("hover").css({ 'background-color':'#c0c0c0' });

            });

            • 3. Re: dynamic button change color on click and reset the unclicked buttons
              Zoze Level 1

              At stageCreationComplete I have it as a function, but it doesn't work correct.

               

              I want to know why.

               

              The problem is that when I use getJSON, it creates the ChildSymbols and keeps in memory only the last record (index).

               

              So, I believe that I need to count the indexes of the JSON files and store it perhaps.

              What I mean.

               

              My JSON structure:

               

              [

                {     "title" : "Central",

                      "category": "",

                  "image": "images/thumbs/models/central.png",

                  "large": "auto-2f-kent-large/0.png",

                      "frame": "frames-large/0.png",

                       "jsonf": "auto2fk.json"

                },

                {     "title" : "Telescopic",

                      "category": "",

                  "image": "images/thumbs/models/telescopic.png",

                  "large": "auto-2f-til-large/0.png",

                      "frame": "frames-large/0.png",

                       "jsonf": "auto2ft.json"

                 

                },

                {     "title" : "Glass",

                      "category": "",

                  "image": "images/thumbs/models/glass.png",

                  "large": "auto-glass-large/0.png",

                      "frame": "frames-large/0.png",

                       "jsonf": "autoglass.json"

                }

              ]

               

              it has 3 index. And on ChildSymbol I give the attr as .attr("id", item.title);

               

              If I make index.length it will give me 3 as number.

               

              But if I make item.title.length it will count the letters of its Word, the result will be (7,10,5).

               

              How Can I make it to count the word itself an give me 3 as a result?