10 Replies Latest reply on Dec 4, 2008 10:57 AM by clbeech

    Flash Calculations

      Sorry I am new to flash and struggling to work out how to calculate prices.

      I have set each of my products a variable price with actionscript 1.0 & 2.0 using the code
      var pricewalkers = 0.50;
      var pricehulahoops = 0.50;
      var pricepastels = 0.50;
      var pricesmarties = 0.45;
      var pricepolos = 0.50;
      I now need to be able to click on the image (which has been converted to a button) and the price appears in a seperate box in the same frame(not sure where this would appear so any ideas on this would be appreciated as well)

      Idealy i would like the price to be multiplied each time the image/button is clicked (released)

      Could you please help with what code is needed for each button and where the price would appear and if possible a code to add up the price when multiple clicks occur.

      Thank you for your help Sam
        • 1. Re: Flash Calculations
          Ned Murphy Adobe Community Professional & MVP
          Create some textfields and give them instance names (ex: walkersTxt).

          Create some variables to associate with each textfield (ex: var walkersTotal = 0;)

          Assign instance names to your image-btns (ex: walkersBtn)

          Here's some code for a button using the examples I offered:

          walkersBtn.onRelease = function(){
          walkersTotal += pricewalkers;
          walkersTxt.text = String(walkersTotal);

          This code would be placed in the same place as your other code.
          • 2. Flash Calculations
            clbeech Level 3
            to 'show' the price, you will need to place a 'textField' on the stage near the item, this is where you would show the current cost. the textfield should be a 'dynamic' type field, this means that you can 'assign' the text within the field during run-time. each time a button is pressed you then calculate the 'new' total using something like this:

            var walkerQty = 0;

            walker_btn.onPress = function() {
            walkerPrice.text = walkerQty * pricewalkers;

            so in this case, i'm assuming that you need to 'track' and store the quantity of walkers the user is asking for, so you would need another set of variables that you can do so. each time the button is pressed the quantity variable is increased by one and the price in the field in recalculated.

            EDIT: sorry there Ned - was typing this up LOL!
            • 3. Flash Calculations
              Ned Murphy Adobe Community Professional & MVP
              Hi Chris, I got a kick out of your head on exact collision with kGlad the other day. Hope you're doing well. I would have posted sooner, but these forums lately are being cranky... it dumped my first response when I tried to post it.

              Well, at least our answers were slightly different, so there'll be something gained from both.
              • 4. Re: Flash Calculations
                clbeech Level 3
                LOL - you bet Ned :) just shows the OP that there are several ways to achieve the goal.

                OT - yeah that was crazy with the kg post, I've never seen times that were identical like that LMAO! :)
                • 5. Re: Flash Calculations
                  sambrown180 Level 1
                  I have the following function:

                  function priceSelection ()
                  {var pricedisplay = "priceSelection"

                  price selection is the function and var pricedisplay is the variable name assigned to the dynamic text box which i want the text to appear in.

                  I now want to click on a button and for the price to go to the dynamic text box.

                  I have set variables of buttons with:
                  var pricepolos = 0.50;
                  var pricetictacs = 0.50;

                  I now want to click the button and price polos and 0.50 to load in the dynamix text box.

                  I have used
                  polos.onPress = function(priceselection) {
                  pricedisplay= "var pricePolos"

                  but it returns an output of undefined when it is run.
                  • 6. Re: Flash Calculations
                    sambrown180 Level 1
                    I just used the code which you have recommended and still get the undefined and no action when the button is clicked any ideas?
                    • 7. Re: Flash Calculations
                      sambrown180 Level 1
                      Sorry just removed text i had below which was tracing a text box and now no errors appear but when i click the instance polosbtn nothing happens at all i have the dynamic textbox called total. and have set the var polosQty = 0; and
                      var pricepolos = 0.50; but nothing happens
                      • 8. Re: Flash Calculations
                        clbeech Level 3
                        ok :) - when assigning text to a textField instance you need to use the 'text' property of the field, also you should not use 'quotes' when assigning a variable value. IF one assigns a method to a value like in the first line above, you must have a 'return' coming from the method being called, and 'passing' the method name within the onPress handler is also not correct. additionally, IF you have assigned a 'variable name' to the textfield - remove it, that is an deprecated system and no longer considered proper usage, instead target the field directly by using an 'instance name' and assign the new value. I aldo don't see a need for the 'priceselction' method, so it should be more like this:

                        var pricepolos = 0.50;

                        polos.onPress = function() {
                        selection.text = "polos"; //actual text string here
                        pricedisplay.text = pricepolos; //variable value here

                        PS - got your PM - you're welcome :)

                        • 9. Re: Flash Calculations
                          sambrown180 Level 1
                          This is driving me crazy lol Right so now I dont need quantity any more?
                          I have the instance name of the dynamic text box set to selection1
                          The button to press is now polosbtn
                          i have var pricepolos = 0.50;

                          I tried the previous post and still no luck there are no errors appearing just nothign happens when i click polosbtn

                          sorry my flash skills are not good at all
                          • 10. Re: Flash Calculations
                            clbeech Level 3
                            lol - don't worry about it, everyone has to start somewhere right :)

                            ok - make sure that you have the instance name assigned to the button in the properties panel. also place a 'trace' statement inside the button handler so you can tell if the call is being made. so you should end up with something more like this: