Packagecom.lafabrick.reflex.controller
Classpublic class BaseController
InheritanceBaseController Inheritance flash.events.EventDispatcher

Base for the creation of a controller


Example

Creation of the data object UserDo

  
  package dataObject
  {
  
      [Bindable]
      [RemoteClass(alias="User.UserDo")]
      public class UserDo
      {
          public function UserDo()
          {
          }
  
          public var login:String;
          public var name:String;
      }
  }
  

Creation of data model UserModel

  
  package model
  {
      import com.lafabrick.reflex.model.BaseModel;
      import dataObject.UserDo;
  
      public class UserModel extends BaseModel
      {
          [Bindable]
          public var userLogged:UserDo;
      }
  }
  
  

Creation of a basic controller UserController

  
  package controller
  {
      import com.lafabrick.reflex.controller.BaseController;
  
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
  
      public class UserController extends BaseController
      {
          
          public function login( log:String, pass:String ) : void
          {
              // execute thedistant method "login", and associate the handlers functions
              executeMethod( "login", onLoginResult, onLoginFault, log, pass);
          }
  
          public function onLoginResult( event:ResultEvent ) : void
          {
              trace("result OK : let's gamble !");
  
              (ModelLocator.getModel( UserModel ) as UserModel).userLogged = event.result as UserDo;
              
          }
   
          public function onLoginFault( event:FaultEvent ) : void
          {
              trace("bad result ..."+event.fault);
          }
      }
  }
  
  

Implementation

  
  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application 
      xmlns:mx="http://www.adobe.com/2006/mxml" 
      layout="absolute" 
      xmlns:controller="controller. 
      xmlns:model="model.>
  
      <mx:RemoteObject id="remoteUser" destination="javaFacadeUser" showBusyCursor="true" />
  
      <controller:UserController id="userControl" service="{remoteUser}" />
      <model:UserModel id="userModel" />
  
      <mx:VBox>
          <mx:TextInput id="login" />
          <mx:TextInput id="password" displayAsPassword="true" />
          <mx:Button label="connect" click="{userControl.login( login.text, password.text )}" />
          <mx:Label x="208" y="44" text="User Name : {userModel.userLogged.name}"/>
      </mx:VBox>
  </mx:Application>
  
  

See also

com.lafabrick.reflex.controller.ControlLocator


Public Properties
 PropertyDefined by
  eventDispatcher : EventDispatcher
Defines an event dispatcher for this controller

In case this dispatcheur is not defines, the distribution channel is the one by default : the controller himself.

BaseController
  service : AbstractService
Defines the AbstractService for this controller

This property must be defines for the functioning of the controller

BaseController
Public Methods
 MethodDefined by
  
executeMethod(method:String, resultFunction:Function, faultFunction:Function = null, ... args):void
Execute a specific method, with some arguments
BaseController
Property detail
eventDispatcherproperty
eventDispatcher:EventDispatcher  [read-write]

Defines an event dispatcher for this controller

In case this dispatcheur is not defines, the distribution channel is the one by default : the controller himself.
To define a dispatcher of event allows for example to obtain a common channel of discussion between the controller and the model

Implementation
    public function get eventDispatcher():EventDispatcher
    public function set eventDispatcher(value:EventDispatcher):void
serviceproperty 
service:AbstractService  [read-write]

Defines the AbstractService for this controller

This property must be defines for the functioning of the controller

Implementation
    public function get service():AbstractService
    public function set service(value:AbstractService):void
Method detail
executeMethod()method
public function executeMethod(method:String, resultFunction:Function, faultFunction:Function = null, ... args):void

Execute a specific method, with some arguments

Parameters
method:String — the name of the method
 
resultFunction:Function — the result handler
 
faultFunction:Function (default = null) — (default null) the fault handler. If null : the controller dispatch the faultEvent
 
... args — arguments to pass