本帖最后由 郎咸蒙 于 2012-11-6 20:38 编辑
- 纯粹脚本的属相 输入年就好了 意在讲解textfeild的使用和显示编程
- package
- {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFieldType;
- import flash.text.TextFormat;
-
- public class AsLearning extends Sprite
- {
- public var arr:Array;
-
- private var btnlbl:TextField;
-
- public function AsLearning()
- {
- arr=new Array("猴","鸡","狗","猪","鼠","牛","虎","兔","龙","蛇","马","羊");
- btnlbl=new TextField();
- btnlbl.text="结果显示";
-
- this.addChild(btnlbl);
- btnlbl.y=30;
- creTxt();
- }
- public function creTxt():void{
-
- var lbl:TextField=new TextField();
-
- lbl.type=TextFieldType.DYNAMIC;
- lbl.width=120;
- lbl.height=20;
- lbl.text='请输入你的出生年月';
-
- lbl.background=true;
- lbl.backgroundColor=0xff3366;
-
- this.addChild(lbl);
- var tf:TextField=new TextField();
-
- tf.type=TextFieldType.INPUT;
- tf.background=true;
- tf.backgroundColor=0x999999;
- tf.height=20;
-
- this.addChild(tf);
-
- tf.x=lbl.x+lbl.width+10;
-
- var btn:Sprite=new Sprite();
-
- btn.useHandCursor=true;
- btn.buttonMode=true;
-
-
- var btnlbl:TextField=new TextField();
- btnlbl.mouseEnabled=false;
- btnlbl.text="获得属性";
- btn.addChild(btnlbl);
- btnlbl.height=20;
- this.addChild(btn);
- btn.x=tf.x+tf.width+20;
-
- btn.addEventListener(MouseEvent.CLICK,onClickHandler);
-
-
-
- }
- private function onClickHandler(e:MouseEvent):void{
-
- //如果你读懂这句就证明你显示编程理解的差不多。
- btnlbl.text=arr[int(TextField(Sprite(e.target).parent.getChildAt(2)).text)%12];
-
- }
-
- }
- }
复制代码 |