WEB开发网
开发学院图形图像Flash Flex中PureMVC 学习小结 阅读

Flex中PureMVC 学习小结

 2009-03-18 12:00:20 来源:WEB开发网   
核心提示: 解释下:public static function getInstance():ApplicationFacade{ if(instance == null){ instance = new ApplicationFacade(); } return instance as Applic

解释下:

public static function getInstance():ApplicationFacade{
            if(instance == null){
                instance = new ApplicationFacade();
            }
            return instance as ApplicationFacade;
        }

这句是获得ApplicationFacade单列工厂,如果不存在则新创建一个,然后返回一个ApplicationFacade.

override protected function initializeController():void{
            super.initializeController();
            registerCommand(AppConstance.START,startCommand);
        }

初始化Controller,并注册了START这个通知与startCommand的映射,注意,通知必须有相关的Command,Mediator对应.

然后创建开始函数:

public function start(app:myApp):void{
            sendNotification(AppConstance.START,app,"myweb");
        }

这里我传了一个参数:app:myApp,意思是传的参数app是myApp类型,myApp指主文件myApp.mxml.

到此ApplicationFacade创建完成,实现了开始函数:start(),单列工厂:getInstance(),还有初始化controller:initializeController();

第三步:

myApp.mxml

myApp属于一个空的Application,在程序开始运行时就需要去执行start();

见代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="intApp()">
    <mx:Script>
        <![CDATA[
            import myApp.ApplicationFacade;
            public function intApp():void{
                var facade:ApplicationFacade = ApplicationFacade.getInstance();
                facade.start(this);
            }
        ]]>
    </mx:Script>
</mx:Application>

上一页  1 2 3 4  下一页

Tags:Flex PureMVC 学习

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接