random.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--http://hje.javaeye.com/blog/275698-->
<!--http://hje.javaeye.com/blog/chat-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="14" layout="absolute" initialize="getnumber();">
<mx:Script>
<![CDATA[
private function getnumber():void{
var number:Number;
number=int(Math.random()*10);
switch (number){
case 1:
msg.text ="one";
break;
case 2:
msg.text = "two";
break;
case 3:
msg.text = "three";
break;
case 4:
msg.text = "four";
break;
case 5:
msg.text = "five";
break;
case 6:
msg.text = "six";
break;
case 7:
msg.text = "seven";
break;
case 8:
msg.text = "eight";
break;
case 9:
msg.text = "nine";
break;
default:
msg.text = "zero";
}
}
]]>
</mx:Script>
<mx:Panel width="250" height="200" layout="absolute" horizontalCenter="114" verticalCenter="-5">
<mx:Label id="msg" text="hello" x="29" y="30"></mx:Label>
<mx:Button id="button1" label="生成随机数" click="getnumber()" x="29" y="89"/>
</mx:Panel>
</mx:Application>