0

I am new to Flash Builder but so far everything is going good. What i am trying to accomplish is using 5 numeric input fields that calculates a total. First of this is a mobile project i am trying to develop, i already have the UI created, i just need the assistance of using these numeric fields and calculating a total just below it.

ketan
  • 19,129
  • 42
  • 60
  • 98

2 Answers2

0
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955"
               minHeight="600">
    <s:layout>
        <s:VerticalLayout />
    </s:layout>

    <fx:Script>
        <![CDATA[
            import spark.events.TextOperationEvent;

            [Bindable]
            protected var total:Number = 0;

            protected function inputChangeHandler(event:TextOperationEvent):void
            {
                var n:Number;
                total = 0;

                n = Number(input1.text);
                if (!isNaN(n))
                    total += n;

                n = Number(input2.text);
                if (!isNaN(n))
                    total += n;

                n = Number(input3.text);
                if (!isNaN(n))
                    total += n;

                n = Number(input4.text);
                if (!isNaN(n))
                    total += n;

                n = Number(input5.text);
                if (!isNaN(n))
                    total += n;
            }
        ]]>
    </fx:Script>

    <s:TextInput id="input1"
                 change="inputChangeHandler(event)" />
    <s:TextInput id="input2"
                 change="inputChangeHandler(event)" />
    <s:TextInput id="input3"
                 change="inputChangeHandler(event)" />
    <s:TextInput id="input4"
                 change="inputChangeHandler(event)" />
    <s:TextInput id="input5"
                 change="inputChangeHandler(event)" />

    <s:Label text="{total}" />

</s:Application>
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
  • The script UI is using a tabbed navigation for a mobile project, Jason this answer you gave me i would need to create a application file or do i just add this into my ui for the mxml? – Dashawn Thompson May 05 '12 at 07:54
0
    <?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="Transaction" xmlns:components="components.*"
        viewDeactivate="callout.close()"
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Declarations>
        <s:RadioButtonGroup id="PaymentMethod"/>
        <components:MyCalloutComp id="callout" height="200" close="location.text=event.data" verticalPosition="after"/>
    </fx:Declarations>
    <s:Label x="17" y="15" color="#1294E7" fontSize="18" fontWeight="bold" text="Method of Payment"/>
    <s:RadioButton x="291" y="46" label="CREDIT CARD" groupName="PaymentMethod"/>
    <s:RadioButton x="11" y="46" label="CASH" groupName="PaymentMethod"/>
    <s:RadioButton x="144" y="47" label="CHECK" groupName="PaymentMethod"/>
    <s:Label x="26" y="90" text="Card Type"/>
    <s:Button x="686" y="413" width="82" label="Print"/>
    <s:Button x="800" y="413" width="96" label="Process"/>
    <s:TextArea x="25" y="175" height="38" maxChars="7"/>
    <s:Label x="25" y="159" text="Drivers License #"/>
    <s:TextInput softKeyboardType="number" x="616" y="34" width="175"/>
    <s:TextInput softKeyboardType="number" x="847" y="33" width="154"/>
    <s:TextInput softKeyboardType="number" x="616" y="106" width="175"/>
    <s:TextInput softKeyboardType="number" x="847" y="103" width="154"/>
    <s:TextInput softKeyboardType="number" x="616" y="180" width="175"/>
    <s:Label x="638" y="17" text="Towing Charge"/>
    <s:Label x="870" y="16" text="Mileage Charge"/>
    <s:Label x="656" y="88" text="Labor Charge"/>
    <s:Label x="849" y="86" text="Extra Person Charge"/>
    <s:Label x="636" y="162" text="Special Equipment"/>
    <s:TextInput softKeyboardType="number" x="847" y="178" width="154"/>
    <s:Label x="867" y="160" text="Storage Charge"/>
    <s:Label x="800" y="264" text="Subtotal"/>
    <s:Label x="815" y="311" fontSize="19" fontWeight="bold" text="Total"/>
    <s:TextInput softKeyboardType="number" x="262" y="106" width="320"/>
    <s:Label x="265" y="89" text="Credit Card Number"/>
    <s:Label x="422" y="159" text="Expiry Date"/>
    <s:TextArea x="622" y="321" width="139" height="38"/>
    <s:DateSpinner x="295" y="274"/>
    <s:TextInput id="location" x="22" y="107" width="205" editable="false" enabled="true"
                 focusIn="callout.open(this.location,true)" text="Select..."/>
</s:View>