1 Reply Latest reply on Jan 16, 2008 6:13 AM by theklue

    Math.max() example

    Tobias Bergström
      Can someone help me with an example (application) where I put in two different numbers, each one in two different TextInputs and a third TextArea/or label show the highest of the both numbers.
      I believe it´s the Math.max() method that does this but I can't find any example anywhere.

      Any other math example might work aswell.

      (I'm a beginner and need an example in code to get it going) Thanks in advance!
        • 1. Re: Math.max() example
          Yes, it's very easy: the Math.max method accepts any number of arguments of type Number and returns the highest. You only need to assign the result of the method to anywhere you want. For example:

          myTextArea.text = Math.max(3, 6, 8);

          You'll see "8" in the text area.

          If you want to get the numbers from a TextArea or a TextInput remember you'll have to cast the values into the correct type using Number(myTx.text).

          Here a full example:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:TextInput id="number1"/>
          <mx:TextInput id="number2" y="40"/>
          <mx:Label text="{Math.max(Number(number1.text), Number(number2.text))}" y="80"/>

          Hope this helps,