Flex MultiCore PureMVC 通知程序初始化错误

发布于 2024-11-10 07:53:52 字数 3071 浏览 0 评论 0原文

我正在尝试编写一个简单的多核 PureMVC helloword。我收到错误:此通知程序的 multitonKey 尚未初始化!

在 org.puremvc.as3.multicore.patterns.observer::Notifier/getfacade()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3_MultiCore\src\org\puremvc\as3\多核\模式\观察者\Notifier.as:89] 在 com.jacksutest.view::ApplicationMediator()[C:\myworkspace\MyPureMVC\src\com\jacksutest\view\ApplicationMediator.as:15]

这是主要的 mxml:

public static const APP_NAME : String = "MyPureMVC";
private var facade : ApplicationFacade = ApplicationFacade.getInstance(APP_NAME);
public function init() : void 
{
facade.startup(this);
}

...
<组件:WordForm id="theWordForm"/>

这是应用程序外观。 公共类 ApplicationFacade 扩展 Facade 实现 IFacade { 公共静态 const STARTUP : String = "启动"; 公共静态 const VERIFY_WORD : String = "VerifyWord";

    public function ApplicationFacade(key:String)
    {
        super(key);
    }

    public static function removeInstance(key:String):void
    {
        if( null != instanceMap ) 
        {
            if( null != instanceMap[key] )
            {
                delete instanceMap[key];
            }
        }
    }

    /**
     * Singleton ApplicationFacade Factory Method
     */
    public static function getInstance(key:String):ApplicationFacade
    {
        if ( null == instanceMap[key] )
        {
            instanceMap[key] = new ApplicationFacade(key);
        }
        return instanceMap[key] as ApplicationFacade;
    }

    /**
     * Register Commands with the Controller
     */
    override protected function initializeController():void
    {
        super.initializeController();
        registerCommand(STARTUP,     StartupCommand);
        registerCommand(VERIFY_WORD, VerifyWordCommand);
    }

    public function startup(app : MyPureMVC):void
    {
        trace("In facade startup");
        sendNotification(STARTUP, app);
    }

    public function verifyWord(wordDTO : WordDTO) : void
    {
        sendNotification(VERIFY_WORD, wordDTO);
    }
}

是启动命令

public class StartupCommand extends MacroCommand
{
    public function StartupCommand()
    {
    trace("Startup command created");
        addSubCommand(ModelPrepCommand);
        addSubCommand(ViewPrepCommand);
    }
}

这是ViewPrepCommand

public class ViewPrepCommand extends SimpleCommand
{
    override public function execute( note : INotification ) : void 
    {
        var app : MyPureMVC = note.getBody() as MyPureMVC;

        facade.registerMediator(new ApplicationMediator(app));
    }
}

这是ApplicationMediator:

public class ApplicationMediator extends Mediator implements IMediator
{
    public static const NAME : String = "MyPureMVCApplicationMediator";
    public function ApplicationMediator(mainApp : MyPureMVC)
    {

        facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
    }

当facade.registerMediator时发生错误。

I am trying to write a simple multicore PureMVC helloword. I am getting Error: multitonKey for this Notifier not yet initialized!

at org.puremvc.as3.multicore.patterns.observer::Notifier/get facade()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3_MultiCore\src\org\puremvc\as3\multicore\patterns\observer\Notifier.as:89]
at com.jacksutest.view::ApplicationMediator()[C:\myworkspace\MyPureMVC\src\com\jacksutest\view\ApplicationMediator.as:15]

Here is the main mxml:

public static const APP_NAME : String = "MyPureMVC";
private var facade : ApplicationFacade = ApplicationFacade.getInstance(APP_NAME);
public function init() : void 
{
facade.startup(this);
}

...
<components:WordForm id="theWordForm"/>

This is the ApplicationFacade.
public class ApplicationFacade extends Facade implements IFacade
{
public static const STARTUP : String = "Startup";
public static const VERIFY_WORD : String = "VerifyWord";

    public function ApplicationFacade(key:String)
    {
        super(key);
    }

    public static function removeInstance(key:String):void
    {
        if( null != instanceMap ) 
        {
            if( null != instanceMap[key] )
            {
                delete instanceMap[key];
            }
        }
    }

    /**
     * Singleton ApplicationFacade Factory Method
     */
    public static function getInstance(key:String):ApplicationFacade
    {
        if ( null == instanceMap[key] )
        {
            instanceMap[key] = new ApplicationFacade(key);
        }
        return instanceMap[key] as ApplicationFacade;
    }

    /**
     * Register Commands with the Controller
     */
    override protected function initializeController():void
    {
        super.initializeController();
        registerCommand(STARTUP,     StartupCommand);
        registerCommand(VERIFY_WORD, VerifyWordCommand);
    }

    public function startup(app : MyPureMVC):void
    {
        trace("In facade startup");
        sendNotification(STARTUP, app);
    }

    public function verifyWord(wordDTO : WordDTO) : void
    {
        sendNotification(VERIFY_WORD, wordDTO);
    }
}

}

This is startup command

public class StartupCommand extends MacroCommand
{
    public function StartupCommand()
    {
    trace("Startup command created");
        addSubCommand(ModelPrepCommand);
        addSubCommand(ViewPrepCommand);
    }
}

This is ViewPrepCommand

public class ViewPrepCommand extends SimpleCommand
{
    override public function execute( note : INotification ) : void 
    {
        var app : MyPureMVC = note.getBody() as MyPureMVC;

        facade.registerMediator(new ApplicationMediator(app));
    }
}

And this is ApplicationMediator:

public class ApplicationMediator extends Mediator implements IMediator
{
    public static const NAME : String = "MyPureMVCApplicationMediator";
    public function ApplicationMediator(mainApp : MyPureMVC)
    {

        facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
    }

Error happens when facade.registerMediator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏雨凉 2024-11-17 07:53:52

找到问题所在。我不应该在 ApplicationMediator 的构造函数中引用facade。

相反,我应该在 onRegister 方法中调用facade.registerMediator。

    public static const NAME : String = "MyPureMVCApplicationMediator";
    public function ApplicationMediator(viewComponent : MyPureMVC)
    {
        super( NAME, viewComponent );
    }
    override public function onRegister():void
    {
        // Retrieve reference to frequently consulted Proxies
        facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
    }

    public function get mainApp() : MyPureMVC
    {
        return viewComponent as MyPureMVC;
    }

Find the problem. I should not reference facade in the constructor of ApplicationMediator.

Instead, I should call the facade.registerMediator in onRegister method.

    public static const NAME : String = "MyPureMVCApplicationMediator";
    public function ApplicationMediator(viewComponent : MyPureMVC)
    {
        super( NAME, viewComponent );
    }
    override public function onRegister():void
    {
        // Retrieve reference to frequently consulted Proxies
        facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
    }

    public function get mainApp() : MyPureMVC
    {
        return viewComponent as MyPureMVC;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文