3 Replies Latest reply on May 11, 2010 11:29 AM by Rothrock

    Radio buttons

    Ron Colmen Level 2

      I've got 2 buttons. I need it to function like radio buttons. When one is clicked I need the other to automatically be invinsible.

       

      if echeck_mc is visible I need echeck_mc to be invinsible. If I'm doing this wrong (marked in red) please show me how should this be coded.

       

      this.check_btn1.onRelease = function() {
      _root.glv_mc.rotate_mc1._visible = !_root.glv_mc.rotate_mc1._visible;
      _root.ltab_mc.echeck_mc._visible = !_root.ltab_mc.echeck_mc._visible;
      if (_root.ltab_mc.echeck_mc._visible = true) {
        _root.ltab_mc.tcheck_mc._visible = false;

      }
      };

        • 1. Re: Radio buttons
          Rothrock Level 5

          The trouble with these things is that you always reuse them or you then need to add a third button and why not make it so that you only have one function that needs to be updated?

           

          var numButtons:Number=2;

           

          for(var i=0;i<numButtons;i++){

               var curButton=this["check_btn"+i];

               curButton.myID=i;

               curButton.onRelease=handleRelease;

          }

           

          function handleRelease(){

               for(var i=0;i<numButtons;i++)}

                    // set everything to invisible

                    // turn everything off

               }

           

               var curNum:Number=this.myID;

               // then use this to turn the specific ones back on that are needed

          }

           

          I couldn't quite figure out the relationships between you btn1 and what it was supposed to turn off/on.

           

          Usually when I'm using multiples of things I also give the other things that they are turning on and off matching numbers so that I know that button0 turns clips with a zero at the end of their name on/off. (Learn to start counting from zero it will help you in the long run.) If the structure of your design is such that you can't give them names like that then you can put them into an array with array element zero (that is why!) corresponding to the radio button that has an ID of zero....

          1 person found this helpful
          • 2. Re: Radio buttons
            Ron Colmen Level 2

            I put my stuff in your code. But it dosen't work

             

            var numButtons:Number=2;

            for(var i=0;i<numButtons;i++){
                 var curButton=this["check_btn"+i];
                 curButton.myID=i;
                 curButton.onRelease=handleRelease;
            }

            function handleRelease(){
                 for(var i=0;i<numButtons;i++){
              _root.glv_mc.rotate_mc1._visible = false;
              _root.ltab_mc.echeck_mc._visible = false;
                 }
            }

                 var curNum:Number=this.myID;{
              _root.glv_mc.rotate_mc2._visible = true;
              _root.ltab_mc.tcheck_mc._visible = true;
              }

            btn1 - I have 2 images and two buttons (btn1 and btn2) when I click on btn1 the rotate_mc1 should appear, rotate_mc1 and  echeck_mc should be invinsible. Same way the oyhwerway

            • 3. Re: Radio buttons
              Rothrock Level 5

              Instead of using tcheck and echeck I would use check0 and check1

               

              function handleRelease(){
                   for(var i=0;i<numButtons;i++){
                          _root.glv_mc["rotate_mc"+i]._visible = false;
                          _root.ltab_mc["check_mc"+i]._visible = false;
                   }

               

              _root.glv_mc["rotate_mc"+this.ID]._visible = true;
              _root.ltab_mc["check_mc"+this.ID]._visible = true;

               

              }

              This is just a different approach to what you are doing and it inolves thinking about the design of your project in a slighly different way. Not saying it is the only or best way, but it is a way that I have found very useful.

               

              if you just can't rename tcheck and echeck then you might need an array

               

              var myNames:Array=["tcheck_mc","echeck_mc"];

               

              function handleRelease(){
                   for(var i=0;i<numButtons;i++){
                          _root.glv_mc["rotate_mc"+i]._visible = false;
                          _root.ltab_mc[myNames[i]]._visible = false;
                   }

               

              _root.glv_mc["rotate_mc"+this.ID]._visible = true;
              _root.ltab_mc[myNames[this.ID]]._visible = true;

               

              }

               

              And the array is why you need to start naming muliples with zero. Because it gets really confusing down the road if you have multiple items and some start at 1 and the arrays that are holding them start at zero.

               

              The cool part is when you go to 3 or 4 items and it is no harder than 2.