topical media & game development

talk show tell print

mashup-rmx-08-RMXFormExample-com-almerblank-rmx-utils-RMXGateway.ax

mashup-rmx-08-RMXFormExample-com-almerblank-rmx-utils-RMXGateway.ax (swf ) [ flash ] flex


  package com.almerblank.rmx.utils
  {
          import flash.net.Responder;
          import mx.managers.CursorManager;
  
          public class RMXGateway
          {
                  // service calls
                  public static const ADD_NEW_MEMBER:String = "Members.addMember";
                  public static const DELETE_MEMBER:String = "Members.deleteMember";
                  
                  // gateway url
                  private static const _gatewayURL:String = "http://www.yoururl.com/amfphp/gateway.php";
                  
                  // gateway variables
                  private static var _gateway:RemotingConnection;
                  private static var _onSuccess:Function;
                  private static var _onFault:Function;
                  
                  
The constructor, should not be used to instantiate a variable as this class is not meant to be instantiated.
returns:

                  
                  public function RMXGateway() {}
                  
                  
The <code>call()</code> method is used to make a remoting call.
parameter: command String path to the remote method being called.
parameter: success Function that is called on a successful communication with the server.
parameter: fault Function that is called when the server returns an error.
parameter: data Data object sent to the remote method
parameter: showBusyCursor Defaults to true to handle the busy cursor while communicating with the server. Set to false if you do not want a busy cursor.

                  
                  public static function call(command:String, success:Function, fault:Function, data:* = null, showBusyCursor:Boolean = true):void
                  {
                          _gateway = new RemotingConnection(_gatewayURL);
                          
                          _onSuccess = success;
                          _onFault = fault;
                          
                          
                          var __responder:Responder = new Responder(onSuccess, onFault);
                          
                          if (data)
                          {
                                  _gateway.call(command, __responder, data);
                          }
                          else
                          {
                                  _gateway.call(command, __responder);
                          }
                          
                          if (showBusyCursor)
                          {
                                  CursorManager.setBusyCursor();
                          }
                          
                          
                  }
                  
                  
Private method that handles firing the function that was specified in the call method and removes the busy cursor.
parameter: result

                  
                  private static function onSuccess(result:*):void
                  {
                          _onSuccess(result);
                          
                          CursorManager.removeBusyCursor();
                  }
                  
Private method that handles firing the fault function that was specified in the call method and removes the busy cursor.
parameter: fault

                  
                  public static function onFault(fault:Object):void
                  {
                          _onFault(fault);
                          
                          CursorManager.removeBusyCursor();
                  }
                  
                  
                  
                  
          }
  }
  
  import flash.net.NetConnection;
  import flash.net.ObjectEncoding;
          
  class RemotingConnection extends NetConnection {
                  
          public function RemotingConnection(sURL:String)
          {
                  objectEncoding = ObjectEncoding.AMF0;
                  if(sURL){
                          connect(sURL);
                  }                
          }        
          
          public function AppendToGatewayUrl(s:String):void{
                  //
          }
  }
  


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.