Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3245393
  • 博文数量: 530
  • 博客积分: 13360
  • 博客等级: 上将
  • 技术积分: 5473
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-13 13:32
文章分类

全部博文(530)

文章存档

2017年(1)

2015年(2)

2013年(24)

2012年(20)

2011年(97)

2010年(240)

2009年(117)

2008年(12)

2007年(8)

2006年(9)

分类: Java

2010-04-18 21:32:25

   swiz使用mediate元数据标签处理事件。

   当你设置配置文件swizconfig中的mediateBubbledEvents为true,你的视图可以简单派发一个事件,该事件将被swiz的DynamicMediator捕获。包含Mediate的这个类必须是一个定义在BeanLoader的类或视图。
    .简单事件
    .事件类
    .优先权
    .
    .控制事件流
    .可撤消事件工作原理
    .非视图类派发事件

简单事件
    // 事件必须设置bubbles为true
    dispatchEvent(new Event("fooEvent", true))

    控制代码
    [Mediate(event="fooEvent")]
    public function fooHandler():void{//...}

事件类
    //事件类
    package example.event
    {
      import flash.events.Event;
 
      public class FooEvent extends Event
      {
        public static const FOO:String = "foo";
 
        public var someValue:String;
 
        public function FooEvent(type:String, someValue:String, bubbles:Boolean=true, cancelable:Boolean=false)
        {
            super(type, bubbles, cancelable);
            this.someValue = someValue;
        }
 
        override public function clone() : Event
        {
            return new FooEvent(type, someValue, bubbles, cancelable);
        }
      }
    }

    视图代码
        dispatchEvent(new FooEvent(FooEvent.FOO, "example"))
    控制代码
        首先设置swizconfig配置文件中的eventPackages=”example.event” 和strict=true。
        [Mediate(event="FooEvent.FOO", properties="someValue")]
        public function fooHandler(someValue:String){//...}

    当swiz处理Mediate 元数据
        .当example.event.FooEvent类存在
        .当类有一个静态常量FOO
        .当类有一个公共成员值

优先级
    如果一个事件被多个类监听,你可能想控制动态监听调用的次序。
    [Mediate(event="FooEvent.FOO", properties="someValue", priority="0")]
    public function secondFooHandler(someValue:String):void{//...}

    [Mediate(event="FooEvent.FOO", properties="someValue", priority="1")]
    public function firstFooHandler(someValue:String):void
    {
        // I am called first because of higher priority
    }
Passing the Event
    Instead of passing properties of an event to the mediating function you can also pass the event itself.
    [Mediate(event="FooEvent.FOO")]
    public function fooEventHandler(event:FooEvent):void

控制事件流
    事件对象还有更多的选择属性,比如停止广播,如下所示
    [Mediate(event="FooEvent.FOO", properties="someValue", priority="0")]
    public function secondFooHandler(someValue:String):void{//...}

    [Mediate(event="FooEvent.FOO", priority="1")]
    public function firstFooHandler(event:FooEvent):void
    {
        // when we call this the event won't bubble further meaning secondFooHandler will never be invoked
        event.stopImmediatePropagation();
    }




阅读(891) | 评论(0) | 转发(0) |
0

上一篇:swiz依赖注入

下一篇:后台框架及软件

给主人留下些什么吧!~~