7 Replies Latest reply on Mar 8, 2009 5:42 PM by Ned Murphy

    Radio Buttons

    gmaguitar01
      am making something similar to a computer builder like dell has. The user has different options, and each option has an assigned price. At the end I want it to display the total price for the items selected. For each screen with hardware I have a code similar to this

      stop();
      onRelease = function (){
      m1 = Number(total)+0;}
      m1.onRelease = function(){
      gotoAndPlay (107)}
      onRelease = function () {
      m2 = Number(total)+150;}
      m2.onRelease = function (){
      gotoAndPlay (107) }
      onRelease = function () {
      m3 = Number(total)+210;}
      m3.onRelease = function (){
      gotoAndPlay (107) }
      onRelease = function () {
      m4 = Number(total)+400;}
      m4.onRelease = function (){
      gotoAndPlay (107) }
      onRelease = function () {
      m5 = Number(total)+450;}
      m5.onRelease = function (){
      gotoAndPlay (107) }


      I am pretty sure I coded it wrong. But as you can see each has an assigned price in which I need it to total at the end. Can someone help me create a total code or help me modify this so I can make a total code
        • 1. Radio Buttons
          Ned Murphy Adobe Community Professional & MVP
          I don't know if radio buttons play a role in this or not. Normally (but not necessarily) radio buttons act as a group, where selecting one deselects any other that is selected. Here's a way to do it with buttons.

          Declare a total variable to start with:

          var total = 0;

          Then, for each click of a button (say "m1" is one button's instance name), add the value associated with it to the total:

          m1.onRelease = function(){
          total += 50;
          }

          The total will build as you go rather than at the end.

          I don't know what's going on with frame 107, so I excluded it from the explanation.

          You could also do this with movieclips that act like buttons and look like radio buttons. Where the first frame would resemble an unselected radio button and the second would resemble a selected radio button. And you could have it add the value when it's being sent to frame 2, and have it subtract the value when it's going back to frame 1.

          If you really want to use radio buttons, then look thru the RadioButton class information in the help files to get an idea of what properties, methods, and events are available for it.
          • 2. Re: Radio Buttons
            gmaguitar01 Level 1
            Thanks, but what would the code look like at the end. Like all the "product pages" completed, I want there to be a final page showing the total price for the items selected. I have no clue what that code would be.
            • 3. Re: Radio Buttons
              Ned Murphy Adobe Community Professional & MVP
              If it's all in the same Flash file, then the only code you might need is the total.

              someTextfield.text = total;

              If you are following the way Dell does things, then you probably want the total showing all of the time so that it updates with each new option change. For the movieclip approach I suggested, where frame 1 would be an unselected option (a blank radio button image), and frame 2 would be a selected item, the code could be as follows...

              m1.onRelease = function(){
              if(m1._currentframe == 1){ // a selection being made
              total += 50;
              m1.gotoAndStop(2);
              } else { // a deselection being made
              total -= 50;
              m1.gotoAndStop(1);
              }
              someTextfield.text = total;
              }

              The code you showed originally is all kinds of wrong. For example, you have m1 first equaling a value, then it suddenly becomes an object that you click on, which takes you away to somewhere-two entirely different things that cannot share the same name.

              I doubt that is really the scenario you want to create. If I remember correctly with Dell, you make numerous selections in a category, then click a button to move to another section of options. Yours seems to take the user away to somewhere for anything they click.

              You probably need to take some time and think thru this, maybe put it on paper to define your step by step logic. Then build code that supports that logic.
              • 4. Re: Radio Buttons
                gmaguitar01 Level 1
                I'm sorry, but I tried what you said and I can't seem to get it to work. I am attaching the file so you can look at it
                Thanks again

                http://www.fileden.com/files/2007/11/9/1573920/computerbuild.fla
                • 5. Re: Radio Buttons
                  Ned Murphy Adobe Community Professional & MVP
                  I looked at your file and don't see anything in there resembling what I suggested. It shows the same errant coding and the use of radio buttons. I won't be doing it for you if you're expecting that to happen.
                  • 6. Re: Radio Buttons
                    gmaguitar01 Level 1
                    That is because I had not saved what you told me because it did not work. At the end all I got for a total was "_level0.total"
                    • 7. Re: Radio Buttons
                      Ned Murphy Adobe Community Professional & MVP
                      Oh well.