1

我正在创建一个 Flash 活动,该活动将被加载到我无法控制的客户框架中。该框架已经加载了一些东西,例如语言环境、字体和副本,并将在初始化时将这些东西传递给我的 swf。

由于我的 swf(我们称之为 shell)的大小受到限制,它会依次显示特定于活动的预加载器,然后将另一个 swf(我们称之为活动)与站点的其余部分一起加载。

shell 和活动都将是 PureMVC 模块。在加载到活动之前,shell 将创建一些代理并使用从框架传递的数据(区域设置常量、字体等)填充这些代理。

加载活动时,它也需要语言环境和字体等。所以我的问题是,将这些数据从 shell 模块传递到活动模块的最佳方法是什么?

  • 我可以在活动模块中创建相同的代理并再次加载数据,这些数据将被缓存,但这显然感觉是错误的方法。

  • 我已经调查了管道实用程序的使用,但在我的情况下这似乎有点矫枉过正,因为通信将是单向的,并且只会在活动初始​​化期间发生一次。

  • 从设计模式的角度来看,将代理传递给活动模块的 init 方法然后在活动模块启动命令中注册这些代理是否“可以”?这似乎是错误的,因为这些代理通过通知名称引用了我的 shell 应用程序外观。如果我将通知名称移动到两个模块都可以使用的某个“NotificationConstants”类,可以吗?

  • 我可以在活动模块中创建类似的代理,但这次使用传递给前面提到的 init 方法的旧代理中的数据对象填充它们?自发地感觉这是最好的方法,因为数据对象没有对我的 shell 模块的任何引用,但“旧”代理有..

4

1 回答 1

2

我通常使用的解决方案是创建一个接口:

interface Campaign {
    function set campaignDetails(value:CampaignDetails):void;

    //...
}

The campaign-module should implement this interface - in the implementation I recommend you to use a different proxy in the module, so that you would avoid having duplicated notifications and references.

When the shell is ready with the loading of the module it just has to:

if (module is Campaign)
{
    (module as Campaign).campaignDetails = ...;
}

I'm sure I'm telling you nothing new. You just need to make sure to keep the acquaintance between the shell and the module only on an interface level. Then you just pass the data and leave the module MVC core to deal with it independently from the shell.

于 2011-10-24T10:24:04.553 回答