摘自: http://blog.csdn.net/Ronniep/archive/2009/09/30/4622347.aspx
本教程是以一个用户自定义模板的Flex 程序.主要功能如下:
1.选取模板布局
2.选择模板颜色风格
3.上传自己的logo
第一步
在Flex 里面new 一个新的工程,名为Dashboard.
设置主文件为myApp.mxml
在src下建立包路径DashBoard
在包下建立3个文件夹.Controller,View,Model.在View下建立UI,Events.在Model下建立VO
将PureMVC的swc文件拷贝到lib下.
到此工程建立.
1.编写ApplicationFacade
源码如下:
package DashBoard
{
import DashBoard.Controller.CreationCommand;
import DashBoard.Controller.CreationSkinCommand;
import DashBoard.Controller.StartCommand;
import org.puremvc.as3.interfaces.IFacade;
import org.puremvc.as3.patterns.facade.Facade;
public class ApplicationFacade extends Facade implements IFacade
{
public static function getInstance():ApplicationFacade{
if(instance == null){
instance = new ApplicationFacade();
}
return instance as ApplicationFacade;
}
override protected function initializeController():void{
super.initializeController();
registerCommand(ApplicationConstance.START,StartCommand);
registerCommand(ApplicationConstance.CREATION_START,CreationCommand);
registerCommand(ApplicationConstance.CREATION_STEP_TW0,CreationSkinCommand);
}
public function start(app:MyApp):void{
sendNotification(ApplicationConstance.START,app,"DashBoard");
}
}
}
解释下:
public class ApplicationFacade extends Facade implements IFacade 新建的ApplicationFacade必须集成于Facade,这个是一个单列模式.
public static function getInstance():ApplicationFacade{
if(instance == null){
instance = new ApplicationFacade();
}
return instance as ApplicationFacade;
}
这个是实例化这个单列,并且整个程序中也就这个facade进行管理.
override protected function initializeController():void{
super.initializeController();
registerCommand(ApplicationConstance.START,StartCommand);
registerCommand(ApplicationConstance.CREATION_START,CreationCommand);
registerCommand(ApplicationConstance.CREATION_STEP_TW0,CreationSkinCommand);
}
注册一些马上需要的command.
public function start(app:MyApp):void{
sendNotification(ApplicationConstance.START,app,"DashBoard");
}
发送START消息,并且带上参数,app,以及type = "DashBoard";
ApplicationConstance.START是消息名,定义在ApplicationConstance中.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Ronniep/archive/2009/09/30/4622347.aspx