想要使用自定义调度事件发送参数 [英] Want to send parameters with custom dispatch event

查看:27
本文介绍了想要使用自定义调度事件发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个库.这是一个例子

I am creating a library. Here is an example

[Event (name="eventAction", type="something")]
            public function create_new_customer(phone_number:String):void
    {
         -------------;
                     ----;
                     ------------;
          rpc.addEventListener(Event.COMPLETE, onCreate_returns);
    }

    private function onCreate_returns(evt:Event):void
    {
         var ob:Object = evt.target.getResponse();
         dispatchEvent(new something("eventAction"));
    }

我在应用程序端有一个此事件的侦听器.所以当我手动调度事件时,我想要ob"作为参数发送.怎么做?

I have a listener to this event in app side. So when I manually dispatch event I want the "ob" to be sent as a parameter. How to do it?

推荐答案

您需要创建一个带有额外属性的自定义事件类,以通过它传递数据.在你的情况下,你可以使用像

You need to create a custom event class with extra properties to pass data with it. In your case you could use a class like

public class YourEvent extends Event
{
    public static const SOMETHING_HAPPENED: String = "somethingHappend";

    public var data: Object;

    public function YourEvent(type:String, data: Object, bubbles:Boolean=false, cancelable:Boolean=false)
    {
        super(type, bubbles, cancelable);

        this.data = data;
    }

    override public function clone():Event
    {
        return new YourEvent (type, data, bubbles, cancelable);
    }

}

然后当你派遣你时:

dispatchEvent(new YourEvent(YourEvent.SOMETHING_HAPPENED, ob));

这篇关于想要使用自定义调度事件发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆