pureMVC 流程

puremve:
1.在页面 close="destroy()"
  creationComplete="init()"
2.在init()方法中facade.startup(RoleConfigNotification.ROLE_CONFIG_STARTUP,this);
3.在Facade中,
registerCommand(RoleConfigNotification.ROLE_CONFIG_STARTUP, RoleConfigCommand);

4.在Command 中,facade.registerProxy(new RoleConfigProxy(RoleConfigProxy.NAME,notification.getBody()));
根据一个notification.getName()来发送一个消息:facade.sendNotification(RoleConfigNotification.ROLE_CONFIG_INIT, notification.getBody());

5.在Mediator中,override public function  listNotificationInterests():Array{}

override public function handleNotification(notification:INotification):void
  {
   switch (notification.getName())
   {
    case RoleConfigNotification.ROLE_CONFIG_INIT:
     //处理业务,调用proxy
  }
}

6.Proxy执行成功:执行result(),发送一个消息:facade.sendNotification(RoleConfigNotification.ROLE_CONFIG_SETDATA,data.result);
   Mediator 接受消息
 执行失败:调用fault()方法
 它实现IProxy,mx.rpc.IResponder这两个接口,继承Proxy类
 它需要private var str:int;public static const NAME:String="RoleConfigProxy";

 proxy调用business

public  function result(data:Object):void
  {
   switch (str)

}

(1)业务:public class RoleConfigBusiness
 {
  private var responder:IResponder;
  private var service:RemoteObject;
  
  public function RoleConfigBusiness(responder:IResponder)
  {
   this.responder = responder;
   this.service = ServicesUtil.getService("roleConfigService");
  }
  
  public function initRoleConfig(pageSize:int): void
  {
   var call:Object = service.initRoleConfig(pageSize);
   call.addResponder(responder); //这两行固定写法,只需要改变一下service的方法名
  }
}

(2)Facade:
public class RoleConfigFacade extends Facade
 {
  public static const NAME:String ="NAME_Role_Config_Facade";
  public function RoleConfigFacade(key:String)
  {
   super(key);
  }
  
  public static function getInstance( key:String ) : RoleConfigFacade
  {
   if ( instanceMap[ key ] == null ) instanceMap[ key ]  = new RoleConfigFacade( key );
   return instanceMap[ key ] as RoleConfigFacade;
  }
  
  override protected function initializeController( ) : void  //需要实现的方法
  {
   super.initializeController();
   registerCommand(RoleConfigNotification.ROLE_CONFIG_STARTUP, RoleConfigCommand);
}}
(3)使用Button(事件监听,调用proxy,查询数据):
view.searchBtn.addEventListener(MouseEvent.CLICK, handleSearch);
private function handleSearch(event:MouseEvent):void{

 var proxy:RoleConfigProxy = facade.retrieveProxy(RoleConfigProxy.NAME) as RoleConfigProxy;
 proxy.search(role_name,itype,status,1,defaultPageSize);//调用proxy
}

 

(4)actionScript对空值的处理:

a.isNaN 函数:

 

(5)数据绑定:需要在mxml文件中定义一个变量:var role:Object;

需要一个与java中的vo对应的actionScript类:

下拉列表comBox: 绑定值需要使用selectedIndex

页面赋值:{role}

在业务层:需要转换成与java的vo对应的actionScript类

你可能感兴趣的:(actionscript)