Flex的自定义事件调度 [英] Flex Custom Event dispatching

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

问题描述

我有一个关于Flex事件调度的问题。

I got a question about event dispatching in flex.

我的目标是获得一个自定义的事件时加载了一些数据,比冒泡的事件监听器。

my goal is to get a custom event loaded up with some data and than bubble up to the eventlistener.

我的主要应用程序和AMF的服务请求在其内部调用一个服务类。该类应该派遣当AMF服务请求返回的结果或故障,主要应用是侦听该事件的事件。

my main application has and AMF service request inside which calls an service class. that class is supposed to dispatch an event when the AMF service request returns a result or fault and the main application is listening for that event.

让我mainapp里面我添加和监听器是这样的:

so inside my mainapp i add and listener like this:

this.addEventListener("UserInfoEvent", userInfoHandler);

自定义UserInfoEvent.as看起来像这样

the custom UserInfoEvent.as looks like this

package events
{
 import flash.events.Event;

 import logic.Ego;

 public class UserInfoEvent extends Event
 {
  private var ego:Ego;

  public function UserInfoEvent(type:String, ego:Ego)
  {
   super(type);
   this.ego = ego;
  }

  override public function clone():Event 
  { 
   return new UserInfoEvent(type, ego);
  } 
 }
}

和最后的AMF服务类中的调度员看起来是这样的:

and finally the dispatcher inside the AMF Service class looks like this:

private var dispatch:EventDispatcher = new EventDispatcher;  
var userInfoEvent:UserInfoEvent = new UserInfoEvent("UserInfoEvent", ego);
dispatch.dispatchEvent(userInfoEvent);

然而,这一事件从未达到的主要应用。仔细观察它与调试器,我发现,当事件被调度它的听众属性设置为null。

However, this event never reaches the main application. Looking closely to it with the debugger, i found out that when the event is dispatched the listeners property of it is set to null.

谁能告诉我什么,我做错了吗?

Can anyone tell me what i'm doing wrong?

推荐答案

你是不是听着,我看到它的正确方法事件。

You are not listening to the event in the right way as I see it.

 // you have 
 this.addEventListener("UserInfoEvent", userInfoHandler);

 // but you dispatch the event from    
 dispatch.dispatchEvent(userInfoEvent);  

这是错误的

您需要有像

instance_of_Dispatch.addEventListener();  // because this != dispatch

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

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