Flash Builder variables -


ok, i'm @ wits' end. i'm noob , that, , it's been awhile since i've done programming sincerity. said, i'm trying , running problems left , right.

my biggest problem has assigning variables. side project, i'm trying create simple calculator using flashbuilder. know it's not done, , has multiple problems. appreciated!

here's code far. what. am. i. missing???

<?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">  <fx:script>     <![cdata[         import mx.events.flexevent;         import spark.components.formitem         import spark.components.textarea;         import spark.components.textinput;          public var n_1:number         public var n_2:number         public var ttl:number = 0       protected function added():void     {     ttl = n1 + n2;     total.text = string(ttl);      }     ]]> </fx:script>    <fx:declarations>      <!-- place non-visual elements (e.g., services, value objects) here --> </fx:declarations>   <s:form id="calc" x="28" y="27">     <s:formitem id="n1" label="1st #">         <s:textinput prompt="number"/>     </s:formitem>     <s:formitem id="n2" label="2nd#">         <s:textinput prompt="number"/>     </s:formitem>     <s:formitem label="total=">         <s:label id="total"/>     </s:formitem> </s:form> <s:button id="add_bn" x="377" y="83" label="+" click="added()"/> <s:button id="minus_bn" x="377" y="123" label="-"/> </s:application> 

you're adding form item form item, receiving not number (nan).

what need textinput text values number.

you make use of data binding, work example:

<?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">      <fx:script>         <![cdata[             import spark.components.formitem;             import spark.components.textinput;              public var n_1:number;             public var n_2:number;             public var ttl:number = 0;              protected function add_bn_clickhandler(event:mouseevent):void             {                 // numbers text field                 n_1 = number(n1.text);                 n_2 = number(n2.text);                  // total:                 ttl = n_1 + n_2;                  total.text = ttl.tostring();             }              protected function minus_bn_clickhandler(event:mouseevent):void             {                 // numbers text field                 n_1 = number(n1.text);                 n_2 = number(n2.text);                  // total:                 ttl = n_1 - n_2;                  total.text = ttl.tostring();             }         ]]>     </fx:script>       <s:form id="calc"             x="28"             y="27">         <s:formitem label="1st #">             <s:textinput id="n1"                          prompt="number" />         </s:formitem>         <s:formitem label="2nd#">             <s:textinput id="n2"                          prompt="number" />         </s:formitem>         <s:formitem label="total=">             <s:label id="total" />         </s:formitem>     </s:form>     <s:button id="add_bn"               x="377"               y="83"               label="+"               click="add_bn_clickhandler(event)" />     <s:button id="minus_bn"               x="377"               y="123"               label="-"               click="minus_bn_clickhandler(event)" /> </s:application> 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -