flex有参数的自定义事件,数据验证测试
来源:互联网 发布:mac触摸板按不下去 编辑:程序博客网 时间:2024/05/17 02:28
自定义带参数的事件应该明白:
(1)自定义事件继承Event时的构造函数里面带参数。
(2)同样需要触发系统事件,然后派发自定义事件。
新建一个ActionScript Class,这个Class继承flash.events.Event。
TransferData.as类代码:
package { import flash.events.Event; public class TransferData extends Event { public static const CUSTOMEVENT:String = "customevent"; public var loginName:String; public var password:String; public function TransferData(type:String, loginName:String, password:String) { super(type); this.loginName = loginName; this.password = password; } override public function clone():Event{ return new TransferData(type,loginName,password); } } }然后创建component来设计并实现数据的传输和接受。
DispatchData.mxml代码如下
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()"> <fx:Metadata> [Event(name="customevent",type="customEvent.TransferData")] </fx:Metadata> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> <mx:Validator id="InputLoginName" source="{loginName}" property="text"/> <mx:Validator id="InputPassword" source="{password}" property="text"/> </fx:Declarations> <fx:Script> <![CDATA[ import mx.controls.Alert; private function init():void{ dispatchData.addEventListener(MouseEvent.CLICK,clickHandle); } private function clickHandle(event:MouseEvent):void{ if(loginName.text != "" && password.text != ""){ canDispatchData(); }else{ Alert.show("Please input the content,contain login name and the password!"); } } private function canDispatchData():void{ var loginEvent:TransferData = new TransferData("customevent",loginName.text,password.text); this.dispatchEvent(loginEvent); } ]]> </fx:Script> <s:Panel x="0" y="0" width="300" height="200" title="The DataSource Panel"> <mx:Form x="10" y="10"> <mx:FormItem label="Login Name:" fontWeight="bold" required="true"> <s:TextInput id="loginName"/> </mx:FormItem> <mx:FormItem label="Password:" fontWeight="bold" required="true"> <s:TextInput id="password"/> </mx:FormItem> <s:Button label="DispatchData" id="dispatchData"/> </mx:Form> </s:Panel> </s:Group>ReceiveData.mxml代码如下
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Panel x="0" y="0" width="300" height="200" title="The DataReceive Panel"> <mx:Form x="10" y="10"> <mx:FormItem label="Login Name:" fontWeight="bold"> <s:TextInput id="loginName" editable="false"/> </mx:FormItem> <mx:FormItem label="Password:" fontWeight="bold"> <s:TextInput id="password" editable="false"/> </mx:FormItem> <s:Button label="ReceiveData" id="receiveData"/> </mx:Form> </s:Panel> </s:Group>LoginEvent.mxml代码
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:component="*" creationComplete="init()" width="900" height="400" > <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.controls.Alert; private var loginName:String; private var password:String; private function init():void{ dispatch.addEventListener(TransferData.CUSTOMEVENT,dispatchData); receive.addEventListener(MouseEvent.CLICK,receiveData); } private function dispatchData(event:TransferData):void{ loginName = event.loginName; password = event.password; Alert.show("loginName:"+loginName+"\npassword:"+password); } private function receiveData(event:MouseEvent):void{ receive.loginName.text = loginName; receive.password.text = password; } ]]> </fx:Script> <component:DispatchData id="dispatch" x="100" y="100"/> <component:ReceiveData id="receive" x="500" y="100"/> </s:Group>在Flex工程主程序里面引入component即可
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:component="*" minWidth="955" minHeight="600" horizontalCenter="0" verticalCenter="0"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Panel title="Show dispatch and receive data" horizontalCenter="0" verticalCenter="0"> <component:LoginEvent/> </s:Panel> </s:Application>
界面如下:
- flex有参数的自定义事件,数据验证测试
- 自定义flex的数据验证组件!
- 自定义flex的数据验证组件!
- flex自定义无参数事件
- flex的自定义事件
- Flex的自定义事件
- flex的数据验证!
- flex的数据验证!
- FLEX验证数据的基本原则
- flex发送带有参数的事件
- flex 添加带参数的监听事件
- Flex自定义事件和组件的使用方法
- 关于flex自定义事件的理解
- Flex自定义事件和组件的使用方法
- flex 初始化时的事件测试
- flex 初始化时的事件测试
- Flex 初始化时的事件测试
- flex---->自定义验证组件
- 60TB传统机械硬盘可能出现
- 网站页面性能优化的34条黄金守则
- 多线程的那点儿事
- mysql 自动备份
- sybase,linux 操作
- flex有参数的自定义事件,数据验证测试
- C++第5周任务【任务2】本任务将设计一个简单的分数类,完成对分数的几个运算。一则巩固基于对象编程的方法,二则也为第10章做运算符重载等积累些感性认识。
- C++第5周任务【任务3】编写基于对象的程序,求5个长方柱的体积和表面积。
- android 在界面上添加一不会消失的按键
- C++第5周任务【任务4】设计一个学生类,包括学号(num)和成绩(score)。建立一个对象数组
- LayoutInflater
- Android的Audio系统(一)
- Onswipe实时触摸操作数据分析工具
- ADF: Foreach和Iterator的区别