参考了:http://hi.baidu.com/chongshe/item/cb0976b7cde4c17e254b09bc之后,发现把登录框独立成Group组件之后,无法触发事件.下面贴下我的全部代码:
1.LoginEvent.as
package { import flash.events.Event; public class LoginEvent extends Event { public static const USER_LOGIN : String = "userLogin"; private var resMsg : String; public function LoginEvent(type:String, resMsg:String, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.resMsg = resMsg; } public function getResMsg() : String { return resMsg; } override public function clone() : Event { return new LoginEvent(type, resMsg); } } }
2.Login.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> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ protected function btnLogin_clickHandler(event:MouseEvent) : void { if (true) { // 这里可以检验登录 : tiUserName.text='用户名' && tiPassWord="密码" var evt:LoginEvent=new LoginEvent(LoginEvent.USER_LOGIN, "登录成功"); parentApplication.dispatchEvent(evt); } } ]]> </fx:Script> <s:Panel title="用户入口"> <s:Form> <s:FormItem label="用户名:" width="100%"> <s:TextInput id="tiUserName" /> </s:FormItem> <s:FormItem label="密码:" width="100%"> <s:TextInput id="tiPassWord" /> </s:FormItem> <s:FormItem width="100%"> <s:layout> <s:HorizontalLayout horizontalAlign="center"/> </s:layout> <s:Button id="btnLogin" width="70" height="25" label="按钮" click="btnLogin_clickHandler(event)" horizontalCenter="0" verticalCenter="0"/> </s:FormItem> </s:Form> </s:Panel> </s:Group>
3.MainApp.mxml:
<?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" minWidth="955" minHeight="600" xmlns:view="*" creationComplete="app_creationCompleteHandler()"> <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.FlexEvent; protected function app_creationCompleteHandler():void { this.addEventListener(LoginEvent.USER_LOGIN, userLoginHandler); } private function userLoginHandler(e:LoginEvent):void{ trace(e.getResMsg()); Alert.show(e.getResMsg(),"提示"); } ]]> </fx:Script> <view:Login verticalCenter="0" horizontalCenter="0" /> </s:Application>
相关推荐
flex4 自定义事件 用法 源码 完整项目导入可运行
Flex4自定义组件 介绍了flex中如何自定义组件以及相关应用
Flex4 自定义通用ImageButton
flex4自定义弹出窗口 支持最大化 最小化
Flex自定义组件和自定义事件的使用。 Flex自定义组件和自定义事件的使用。
flex 高级自定义组件 需要重写的方法,以及为什么要重写,何时调用等。
你还在头痛flex4组件皮肤怎么自定义吗?看我给你们上传的吧;因皮肤中还是有部分mx组件,如果不能正常使用,请自己把所以mx组件改成sp组件
NULL 博文链接:https://whp0731.iteye.com/blog/726223
预览地址: http://www.iflex4.com/samples/picviewer/picviewer.html http://www.iflex4.com/samples/picviewer/app.html 更多信息请访问: www.iflex4.com Flex4视频教程免费下载。
一个完成的Flex4 Air 自定义窗口,可以缩小到托盘中,后台运行
NULL 博文链接:https://futurewwm.iteye.com/blog/1277119
flex事件flex事件flex事件flex事件flex事件
flex自定义组件事件DEMO,一个简单的flex自定义组件的demo
flex开发自定义控件
NULL 博文链接:https://demojava.iteye.com/blog/1159535
使用Flex ,AS,实现的适用于Flex Mobile平台的对话框。
flex TitleWindow自定义最大最小化
flex 自定义组件,UI,flex 自定义组件。
flex自定义事件的含义 简单例子说明 。。。。。。。。。。
通过两种方法继承List组件的IconItemRenderer,实现在每个item项中添加组件,如button等