我只是得到了编码的窍门,这在很大程度上归功于这个网站......但我还是noob,并有另一个noob问题。Flash Builder组件和循环
我创建了一个简单的计算器,我的孩子可以用它来处理他们的数学技能,但是我不知道如何循环它以便它会去10次。我理解for-else和until循环的语法,但不知道要在循环中放置什么。
做到这一点(我认为)最简单的方法可能是使用组件或类(不知道使用哪一个)然后调用它。
这就是说,这里是我的基本代码:
<?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 = Math.round(Math.random() * 100)
public var n_2:Number = Math.round(Math.random() * 100)
public var ttl:Number
public var answer:Number
public var n_right:int
public var n_total:int = 1
protected function check_bn_clickHandler(event:MouseEvent):void
{
n1.text = n_1.toString();
n2.text = n_2.toString();
ttl = Number(total.text);
answer = n_1 + n_2
if(ttl == answer) {
yes_no_lbl.text = "YES, click NEXT!";
n_right = n_right + 1
} else {
yes_no_lbl.text = "NO, try again!";
}
}
protected function next_bn_clickHandler(event:MouseEvent):void
{
// reset variables
n_1 = 0
n_2 = 0
ttl = 0
// use component here????
}
]]>
</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 label="1st #">
<s:Label id="n1" text = "{n_1.toString()}"/>
</s:FormItem>
<s:FormItem label="2nd#">
<s:Label id="n2" text = "{n_2.toString()}"/>
</s:FormItem>
<s:FormItem label="Total=">
<s:TextInput id="total" prompt="Total"/>
</s:FormItem>
</s:Form>
<s:Button id="check_bn" x="273" y="124" label="Check" click="check_bn_clickHandler(event)"/>
<s:Button id="next_bn" x="377" y="123" label="Next" click="next_bn_clickHandler(event)"/>
<s:Form id="display_correct" x="649" y="27">
<s:FormItem label="# Correct">
<s:Label id="lbl_ratio" text="{n_right}/{n_total} "/>
</s:FormItem>
</s:Form>
<s:Label id="yes_no_lbl" x="462" y="83" width="184" height="61"/>
</s:Application>
那么其中有多少是我放的组成部分,多少钱,我留在应用程序?或者是否有像“重绘”这样的功能,可以再次运行该应用程序,但只保留长期变量(n_right等)?再次
谢谢!
嗯...好吧,你是对的我需要这样做,但无法弄清楚语法。在声明中,例如:'public var ttl:Number'在哪里添加'[Bindable]'?我尝试了很多地方,它总是让我犯错。谢谢! – nebmuzik 2012-03-08 15:17:18
[Bindable] public var n_1:Number ..... – Eduardo 2012-03-08 15:31:30
编辑答案的文本以显示 – Eduardo 2012-03-08 15:32:18