2 Replies Latest reply on Nov 3, 2009 6:05 PM by MudkipsAreCool

    Need help making a function

    MudkipsAreCool

      Hello

       

       

      I am trying to make an application the calculates the cost of movie tickets. I am having 10 rows, each row being used to calculate the cost of one ticket. A checkbox is used to enable each row of objects so that the user can input the age (just age for now, adding time and date later) and get the ticket cost in return. My problem is that I am unable to figure out how to make a function that 1: Says [ if Numericstepper.value <= "anumber" then "a variable string that I have set" = "something"] . Whenever I try to type WhatAge <= "12" I get an invalid character in the scriptblock error. How would I go about doing something like

       

      If NumericStepper.value <= "13"

      then WhatAge = Child

       

      Because I keep getting invalid character errors with the "<"

       

      As well, how do I make it so that a function can be called by every row (every checkbox). For example, clicking Box1 will enable all of the objects in that boxrow (numericstepper 1), which is easy enough to do but I don't want to have to write 10 functions, one for each checko. How do I write a function that can be called by every checkbox, say, Box2 and will enable numericstepper2, box3 for NS3 and so on?

       

      Thanks for your help!

        • 1. Re: Need help making a function
          Matt Le Fevre Level 4

          How do I write a function that can be called by every checkbox, say, Box2 and will enable numericstepper2, box3 for NS3 and so on?

           

          don't even really need a function for that, just bind the Numeric stepper enabled attribute to the relevant checkbox, eg;

          <mx:NumericStepper id="NS2" enabled="{Box2.selected}"/>
          
          <mx:NumericStepper id="NS3" enabled="{Box3.selected}"/>
          

           

           

          [ if Numericstepper.value <= "anumber" then "a variable string that I have set" = "something"]

           

          annnnnnnd bind a function onto the 'change' attribute;

          <mx:NumericStepper id="NS2" change="doThis()"/>
          
          public var exampleString:String;
                         
          private function doThis():void
          {
               if (NS2.value <= 13)
               {
                    exampleString = "Child";
               }
               else
               {
                    exampleString = "Adult";
               }
          }
          

           

           

          Because I keep getting invalid character errors with the "<"

           

          well if you're saying:

           

          numbericStepper.value <= "13"

           

          and wrapping the 13 in quotes, flex won't understand, as you're trying to compare a value(numerical value) to a string value("13"), just write 13

          1 person found this helpful
          • 2. Re: Need help making a function
            MudkipsAreCool Level 1

            Wow, thank you very much for your help