经常换外币就写了一个外币兑换程序, 在xml里面输入外币的种类和兑换率,然后前台就可以直接显示:
代码如下: package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.Event; import flash.net.URLRequest; import flash.net.URLLoader; import flash.system.System; import flash.text.TextFormat; import fl.controls.TextInput; import fl.controls.Button; import fl.controls.ComboBox; import fl.controls.Label; public class moneyChange extends Sprite { private var _textInput:TextInput; private var _recordText:TextInput; private var _button:Button; private var _comBox:ComboBox; private var _labelabel; private var _reLabelabel; private var _num:Number; private var _myFormat:TextFormat; private var _inputText:Number; private var _indexNum:uint; private var myXml:XML; private var _moneyAry:Array= new Array(); private var _changeAry:Array=new Array(); System.useCodePage = true; public function moneyChange() { var _urlLoader:URLLoader = new URLLoader(new URLRequest("money.xml")) _urlLoader.addEventListener(Event.COMPLETE,completeHandler) showCom(); } private function completeHandler(evt:Event):void{ myXml = new XML(evt.target.data) _comBox = new ComboBox(); _comBox.move(225,80); _comBox.textField.setStyle("textFormat",_myFormat) _comBox.dropdown.setRendererStyle("textFormat", _myFormat); for(var i:uint = 0;i<myXml.moneys.length();i++){ _moneyAry.push(myXml.moneys.money) _changeAry.push(myXml.moneys.change) _comBox.addItem({label:_moneyAry,data:_changeAry}) } _comBox.dropdownWidth = 100 _comBox.rowCount = 5; addChild(_comBox); _comBox.addEventListener(Event.CHANGE,changeHandler) } private function showCom():void { _myFormat = new TextFormat() _myFormat.font = "_self"; _myFormat.color = 0xff0044; _myFormat.size = 12 _label = new Label(); _label.move(100,50) _label.text = "请输入金额:" addChild(_label) _label.setStyle("textFormat",_myFormat) _reLabel = new Label(); _reLabel.move(350,50) _reLabel.text = "兑换人民币的结果" addChild(_reLabel); _reLabel.setStyle("textFormat",_myFormat) _textInput = new TextInput(); _textInput.move(100,80); _textInput.restrict = "0-9,." addChild(_textInput); _recordText = new TextInput(); _recordText.move(350,80); addChild(_recordText); _button = new Button(); _button.move(225,130); _button.label = "兑换"; addChild(_button); _button.addEventListener(MouseEvent.CLICK,clickHandler); _button.setStyle("textFormat",_myFormat) } private function clickHandler(evt:MouseEvent):void{ _recordText.text = (Number(_textInput.text)*_changeAry[_indexNum]).toFixed(3).toString(); } private function changeHandler(evt:Event):void{ _indexNum = evt.target.selectedIndex _inputText = Number(_textInput.text) ; _recordText.text = (_inputText*_changeAry[_indexNum]).toFixed(3).toString(); } } } 附件
|
|
|