<? xml version="1.0" encoding="utf-8" ?> <!-- 版本号(必选)和编码格式(可选) --> < mx:Application xmlns:mx ="http://www.adobe.com/2006/mxml" layout ="absolute" creationComplete ="initApp()" > <!-- layout="absolute" 布局方式:绝对定位 --> < mx:Button x ="10" y ="21" label ="Button" id ="btn" labelPlacement ="right" width ="97" icon ="@Embed('file:///E|/图片/美女/1.jpg')" /> <!-- 使用Icon时,图像文件必须直接被嵌入在SWF中,不仅要指定文件路径,还需要在路径前加上“Embed”标示字样。 --> < mx:Label x ="154" y ="22" text ="我是一个标签" id ="label_tip" enabled ="true" /> < mx:Style > //全局样式表代码来设置界面上所有文字大小和程序背景 Application{ fontSize:20; backgroundGradientColors:#c0c0c0,#c0c0c0; } </ mx:Style > < mx:Script > <![CDATA[ //导入类 import flash.events.MouseEvent; internal function initApp():void{ //给按钮添加点击事件监听方法 //.所有的可视化组件都有addEventListener方法,用于添加对特定事件的监听函数。 //addEventListener(type:String,listener:Function,useCapture:Boolean=false,priority:int=0,useWeakference:Boolean=false)前两个参数最重要,同时也必不可少,分别对应事件的类型和对应的执行函数名。 btn.addEventListener(MouseEvent.CLICK,doClick); } //事件相应函数 internal function doClick(evt:MouseEvent):void{ btn.enabled=false; label_tip.text="我是点击后的标签!!"; } ]]> </ mx:Script > </ mx:Application >