转自:百度
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12"
creationComplete="createCompleteHandler(event)">
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
private const NL:String = "\r";
private function submitButtonClickHandler(event:MouseEvent):void
{
if(txtname.text=="")
{
Alert.show("请输入您的大名!","配合一下不可以么?",4,null,4);
return;
}
//var all:String="你已经点击的按钮";
//Alert.show(all,"按钮的处理程序",4);
var all:String="测试清单:"+NL+NL;
all+="姓名:"+txtname.text+NL;
all+="心情:"+cmbmood.text+NL;
Alert.show(all,"",4);
}
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import flash.events.MouseEvent;
private function createCompleteHandler(event:FlexEvent):void
{
btnfouth.addEventListener(MouseEvent.CLICK,clickHandler);
}
private function clickHandler(event:Event):void
{
lblword.text="hello word";
}
]]>
</mx:Script>
<mx:Panel title="这是一个panel层" layout="vertical" width="50%" paddingLeft="10"
paddingRight="10" paddingTop="10">
<mx:Form width="100%">
<mx:FormItem label="姓名" width="50%">
<mx:TextInput id="txtname"/>
</mx:FormItem>
<mx:FormItem label="选择你现在的心情:" width="50%">
<mx:ComboBox id="cmbmood" width="100%">
<mx:Array>
<mx:Object data="好" label="好"/>
<mx:Object data="一般" label="一般"/>
<mx:Object data="差" label="差"/>
</mx:Array>
</mx:ComboBox>
</mx:FormItem>
</mx:Form>
<mx:ControlBar horizontalAlign="center">
<mx:Button id="sub" label="submit" click="submitButtonClickHandler(event)"/>
</mx:ControlBar>
</mx:Panel>
<mx:Panel title="应用一个panel" layout="absolute" width="50%" x="400" y="260">
<mx:Label id="lblword" text="HELLO WORDER" fontSize="24" fontWeight="bold" x="200"/>
<mx:ControlBar horizontalAlign="center">
<mx:Button id="btnshow" label="淅沥的小雨不停的下">
<mx:click>
<![CDATA[
import mx.controls.Alert;
Alert.show("下雨吧~~~","不要停下来",4);
]]>
</mx:click>
</mx:Button>
<mx:Button id="btnthd" label="click的第三种写法" click="lblword.text='你好么'"/>
<mx:Button id="btnfouth" label="click的第四种写法"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
说明:FlexAboutButton.mxml中汇总了button的click事件的写法
第一种click事件触发,调用一个方法[写在Script中的方法]
click="submitButtonClickHandler(event)"
第二种click事件触发,调用的方法写在按钮的内部
<mx:Button id="btnshow" label="淅沥的小雨不停的下">
<mx:click>
<![CDATA[
import mx.controls.Alert;
Alert.show("下雨吧~~~",4);
]]>
</mx:click>
</mx:Button>
第三种click事件触发
click="lblword.text='你好么'"
第四种click事件,是在页面加载完成以后触发的事件中注册的方法
1 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="createCompleteHandler(event)"> 2 <mx:Script> <![CDATA[ import mx.events.FlexEvent; import flash.events.MouseEvent; private function createCompleteHandler(event:FlexEvent):void { btnfouth.addEventListener(MouseEvent.CLICK,clickHandler); } private function clickHandler(event:Event):void { lblword.text="hello word"; } ]]> </mx:Script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。