9 Replies Latest reply on Jun 17, 2011 2:15 PM by kglad

    Button

    TabriziS

      Hi all,

       

      I have 2 buttons and one object.

      when I move over the button #1 the color of the button #1 changes and the object appears

      when I move over the button #2 the object appears

       

      What I want to be able to do is :

      when I move over the button #2 I want the color of the button #1 to change

       

       

      p.s. for changing the button color I'm simply using the over frame in the button

      for the object I'm using the load request (as3)

       

      Thanks

        • 1. Re: Button
          kglad Adobe Community Professional & MVP

          in you button #2 rollover listener function:

           

          // // use button#1's correct reference instead of <button#1>

          var ct:ColorTransform=<button#1>.transform.colorTransform;

          ct.color=0xff0000;

          <button#1>.transform.colorTransform=ct;

          • 2. Re: Button
            TabriziS Level 1

            Thanks for your reply, but it only changes the color of the button #1

            from my previous color to pink when I move over Button #1, but

            I want it to change the color of button #1 when I move over #2 as well

            here is the code:

             

             

            BtnOne.addEventListener(MouseEvent.MOUSE_OVER, getImageOne);

            BtnTwo.addEventListener(MouseEvent.MOUSE_OVER, getImageTwo);

             

                function getImageOne(evt:MouseEvent):void{
                var picURL:URLRequest = new URLRequest("1.jpg");
                loadRequest.load(picURL);
                McCont.addChild(loadRequest);
                }

             

                function getImageTwo(evt:MouseEvent):void{
                var picURL:URLRequest = new URLRequest("1.jpg");
                loadRequest.load(picURL);
                McCont.addChild(loadRequest);
               
                var ct:ColorTransform=BtnOne.transform.colorTransform;
                ct.color=0xff0000;
                BtnOne.transform.colorTransform=ct;
                }

            • 3. Re: Button
              kglad Adobe Community Professional & MVP

              that code will change the color of BtnOne when BtnTwo is moused-over.

               

              if you think you're seeing something else, it's not because of that code.

              • 4. Re: Button
                TabriziS Level 1

                There aren't any errors, it works fine, it's just that when I mouse over the button2,

                object shows up without the button 1 changing color.

                 

                It seems that it has to work, but it doesn't, that's the beauty of coding!!

                • 5. Re: Button
                  kglad Adobe Community Professional & MVP

                  you're doing something wrong.  download and check:  www.kglad.com/Files/forums/Untitled-4.fla

                  • 6. Re: Button
                    TabriziS Level 1

                    Huh, you know what was causing the problem?!!!

                    my button was actually a button symbol as of yours is a movie clip

                    acting as a button, I changed mine to a movie clip and it works fine!!

                    so there, that was the problem

                     

                    Thanks a lot for the file, it was a great help, without it I would have thought

                    there is something wrong with my code !!

                     

                    One issue now, with the button symbol, the color was gone when I moved the

                    mouse away, but this way the color changes and stays, even when the mouse is

                    moved away!! I know I have to somehow add a code for the mouse away part

                    I just don't know how!!

                    • 7. Re: Button
                      kglad Adobe Community Professional & MVP

                      use:

                       


                       

                      BtnOne.addEventListener(MouseEvent.MOUSE_OVER, getImageOne);

                      BtnTwo.addEventListener(MouseEvent.MOUSE_OVER, getImageTwo);

                      BtnTwo.addEventListener(MouseEvent.MOUSE_OUT, outF);

                       

                          function getImageOne(evt:MouseEvent):void{
                          var picURL:URLRequest = new URLRequest("1.jpg");
                          loadRequest.load(picURL);
                          McCont.addChild(loadRequest);
                          }

                       

                          function getImageTwo(evt:MouseEvent):void{
                          var picURL:URLRequest = new URLRequest("1.jpg");
                          loadRequest.load(picURL);
                          McCont.addChild(loadRequest);
                         
                          var ct:ColorTransform=BtnOne.transform.colorTransform;
                          ct.color=0xff0000;
                          BtnOne.transform.colorTransform=ct;
                          }

                       

                        function outF(evt:MouseEvent):void{
                        
                         
                          var ct:ColorTransform=BtnOne.transform.colorTransform;
                          ct.color=0x00ff00;
                          BtnOne.transform.colorTransform=ct;
                          }
                      1 person found this helpful
                      • 8. Re: Button
                        TabriziS Level 1

                        Thanks, this works fine, now I have to think functional  ....

                         

                        I need to create 100 sets of each button, therefore I have to somehow

                        combine the codes because there are 20 line of codes for each set

                        of buttons 20x100=2000

                         

                        and this is just for the button part of the file, let alone other functions of

                        the page

                         

                        maybe I'll create a function to unload/remove the color + object when mouse

                        is moved away, I have a long way ahead of me

                         

                        ohhh, how I enjoy coding (NOT!)

                        • 9. Re: Button
                          kglad Adobe Community Professional & MVP

                          you should be able to encode that in a for-loop so there aren't many lines of code.  the only issue is how to handle the color associated with each movieclip button's mouseover and mouseout.  at the worst, you'll need to use an array of colors.  at the best, there may be some rule to use for each movieclip button.