zoukankan      html  css  js  c++  java
  • Flex 自定义事件2

    LoginEvent.as
    package events
    {
        import flash.events.Event;
        import datas.UserInfo;

        public class LoginEvent extends Event
        {
            public 
    function LoginEvent(user:UserInfo,type:String){
                super(type);
                
    this.user = user;
            }
            public 
    var user:UserInfo;        
        }
    }

    UserInfo.as
    package datas
    {
        public class UserInfo
        {
            public 
    var name:String;
            public 
    var password:String;
        }
    }

    LoginControl.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="290" height="132">
    <mx:Metadata>
        [Event(name="login",type="events.LoginEvent")]
    </mx:Metadata>
    <mx:Script>
        
    <![CDATA[
            import datas.UserInfo;
            import events.LoginEvent;
            public function login():void
            {
                var user:UserInfo = new UserInfo();
                user.name = this.txtUser.text;
                user.password = this.txtPassword.text;
                
                var event:LoginEvent = new LoginEvent(user,"login");
                this.dispatchEvent(event);
            }
        
    ]]>
    </mx:Script>
        
    <mx:Button x="224" y="100" label="Login" click="login()"/>
        
    <mx:Form x="10" y="10" width="270">
            
    <mx:FormItem label="User Name:" required="true">
                
    <mx:TextInput maxChars="10" id="txtUser"/>
            
    </mx:FormItem>
            
    <mx:FormItem label="Password:" required="true">
                
    <mx:TextInput displayAsPassword="true" maxChars="8" id="txtPassword"/>
            
    </mx:FormItem>
        
    </mx:Form>
        
    </mx:Canvas>

    EventTest.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" width="360" height="185">
    <mx:Script>
        
    <![CDATA[
            import mx.controls.Alert;
            import datas.UserInfo;
            import events.LoginEvent;
            
            private function loginHandler(event:LoginEvent):void{
                mx.controls.Alert.show(event.user.name +" log in.");
                
            }
        
    ]]>
    </mx:Script>
        
    <ns1:LoginControl x="27" y="24" login="loginHandler(event)" width="301" height="135">
        
    </ns1:LoginControl>
        
    </mx:Application>



    测试:
  • 相关阅读:
    Java实现Http请求的常用方式
    Java中Map和Object的互相转换方式
    java中过多if-else分支语句的优化方案
    将一个数组,以特定的字符拼接成字符串
    括号匹配算法
    面试题随笔1
    Docker run 的一些简单命令
    集群,负载均衡,分布式的区别
    Docker 容器的常用命令
    web应用常用的CURL基本命令
  • 原文地址:https://www.cnblogs.com/mobile/p/636733.html
Copyright © 2011-2022 走看看