首先我们先写一个自定义的登录事件。
loginformEvent.as:
package com.events//包,可以理解成目录,在com/events/下
{
import flash.events.Event;
public class loginformEvent extends Event
{
public var name:String = "";
public var pwd:String = "";
//构造函数
public function loginformEvent(type:String)
{
super(type, false, false);//调用父类的构造函数
}
//flex中的方法重写原来是这个样,就顺便写到这了。
override public function clone():Event
{
return new loginformEvent(type);
}
}
}
然后我们就写自定义组件吧
LoginForm.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="206" fontSize="12">
<mx:Metadata>
[Event(name="MyEvent",type="com.events.loginformEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import com.events.loginformEvent;//引入自定义的事件类
internal function OnClick(evt:MouseEvent):void{
var e:loginformEvent = new loginformEvent("MyEvent");
e.name = user.text;//把用户名赋给自定义事件中的name
e.pwd = pwd.text;
this.dispatchEvent(e);//事件派发
}
]]>
</mx:Script>
<mx:Label x="65" y="33" text="用户名:" fontWeight="bold"/>
<mx:Label x="65" y="84" text="密码:" fontWeight="bold"/>
<mx:TextInput x="164" y="82" id="pwd" displayAsPassword="true"/>
<mx:Button x="164" y="132" label="登录" id="btn" click="OnClick(event)"/>
<mx:TextInput x="164" y="31" id="user"/>
</mx:Panel>
最后就是我们的主要文件了。
main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
<mx:Script>
<![CDATA[
import com.events.loginformEvent;//引入自定义的事件类
import mx.controls.Alert;
internal function login(evt:loginformEvent):void{
if(evt.pwd=="admin" && evt.name=="admin"){
Alert.show("成功登录!","提示");
}else{
Alert.show("登录失败!","提示");
}
}
]]>
</mx:Script>
<ns1:LoginForm x="133.5" y="71" MyEvent="login(event)"><!--这里要注意自定义组件中有个MyEvent-->
</ns1:LoginForm>
</mx:Application>
===================================================
个人理解:
1、事件的传递,有内层组件----》》外层组件,即在本例中由【LoginForm】组件 dispatch(分发事件)给它的上层组件【main】,形象点的比喻:内层组件发起的事件,引起了上层组件的联动。
分享到:
相关推荐
spring自定义注解样例
spring自定义切面实例.txt
spring的自定义标签代码工程样例,Chapter2工程
本代码使用H2内存数据库演示spring事务使用,包括编程式事务,声明式事务@Transactional使用,自定义事务事务注解实现自定义事务管理器
在spring环境中通过component-scan配置处理自定义java注解
spring自定义编辑器的简单使用。
NULL 博文链接:https://wooden-baby.iteye.com/blog/506838
主要是讲spring自定义xml配置的扩展相关的内容,东西不算新的,都是比较基础的,想看就看一下 我也是为了搞点积分才上传的
利用Spring Context上下文创建自定义对象,学习Spring的IoC容器如何使用控制反转创建一个对象,了解Spring控制反转原理
Spring 5.2.9 06 源码分析-spring自定义标签解析过程
spring自定义注解+Aspect使用1
使用spring mvc 和spring security 完成简单的自定义登录
用于自定义spring xml标签, 例如 <dubbo:service /> 标签
Spring 5.2.9 06 源码分析-spring自定义标签解析过程
Spring5.0自定义配置文件便签[Maven]工程可运行【spring-customize-tag】
Spring 自定义注解注入properties文件的值jar包,下面为使用方法 在xml配置文件中,这样加载properties文件 ...
主要介绍了这一次搞懂Spring自定义标签以及注解解析原理说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
3、对spring aop认识模糊的,不清楚如何实现Java 自定义注解的 4、想看spring aop 注解实现记录系统日志并入库等 二、能学到什么 1、收获可用源码 2、能够清楚的知道如何用spring aop实现自定义注解以及注解的逻辑...
Spring security的完整使用范例,支持自定义密码的加密方式,以及成功,失败的处理。是一个完整可运行的工程,码云似乎还要注册。后期考虑下用码云
spring aop 自定义切面示例 aspectj 需要相应的架包支持