【发布时间】:2013-01-12 01:56:41
【问题描述】:
只是想我会分享一些我发现的东西来帮助跨应用程序传递数据我想知道其他人对此有何看法使它易于在 May 应用程序的任何地方使用,所以这就是我想出的。
我扩展 Application 类并包装在一个抽象函数中,该函数在任何地方注册任何组件的函数,并在最顶层捕获它并传递到我选择的任何地方。
public class AxApplication extends Application
{
public var ___registeredEvents:Array = new Array();
public var ___registeredFunctions:Array = new Array();
function AxApplication()
{
super();
}
public function localRegisterForEvent(e:Event,func:*,caller:*):void
{
caller.addEventListener(e.type,localCallerEventHandler,true,3);
caller.addEventListener(e.type,localCallerEventHandler,false,3);
___registeredEvents.push(e);
___registeredFunctions.push(func);
}
public function localCallerEventHandler(e:*):void
{
if(e!=null)
{
for(var i:int = 0 ; i< ___registeredEvents.length; i++)
{
if(e.type == ___registeredEvents[i].type)
{
___registeredFunctions[i](e);
//注册的函数被调用 //没有实现垃圾回收!
}
}
}
}
}
【问题讨论】:
-
我想我应该提到的一件事是如何使用它你可以像这样使用它:
-
AxApplication(this.parentApplication).localRegisterForEvent(new Event(Event.SOME_EVENT),someFunctionHandler,callingObject);调用对象就是将输出事件的对象,只要您在应用程序中注册该对象一次,它就会将其传递回任何地方,而无需任何编码以多次获取数据。
标签: actionscript-3 events design-patterns data-binding flash-builder