The First and Only Magazine for Macromedia MX™
   
 
Notes from the Flash, Flex and ColdFusion trenches

Category List

Quick Poll

Where are you located?
North America
South America
Europe
Asia
Africa
Australia

My RSS Feeds








Hit Counter

Total: 1,305,972
since: 20 Jan 2005

Search Box

 

Search The Web

Google

MAX 2008

Fun Stuff

Mailing List

Got A Question?

Got A Question?

Leave a comment by the appropriate Entry, or email me

Tag Cloud

                                                                                                                       

Creating a Remote Object DataManager in ActionScript 3.0 for Flex 2.0

posted Wednesday, 4 January 2006

Tien Nguyen followed up on my WebService DataManager with one for RemoteObject as well.
I haven't had a chance to try it myself yet, but this RemoteObject DataManager should work through the CFAdapter for more efficient data transport with ColdFusion Components


package managers {
    import flash.events.EventDispatcher;
    import flash.util.*;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.AbstractOperation;
    import mx.rpc.remoting.mxml.RemoteObject;
    import mx.utils.ObjectUtil;
    import events.DataManagerResultEvent;
    import mx.controls.Alert;
 
  /**
   DataManager - singleton class which enforces only
   a single object is created for each service.  To
   access DataManager, use getDataManager(cfservice:String)
  */
 
    public class DataManagerCF extends EventDispatcher {
        private var CFsvc:RemoteObject;
        private var eventName:String;
 
        // hashmap of instances for each service
        private static var instanceMap:Object = new Object();
 
        public function DataManagerCF(pri:PrivateClass,dest:String){
            this.CFsvc = new RemoteObject();
            CFsvc.destination = dest;
        }
 
        public static function getDataManager(CFsvc:String):DataManagerCF{
          if(DataManagerCF.instanceMap[CFsvc] == null){
               DataManagerCF.instanceMap[CFsvc] = new DataManagerCF(new PrivateClass(),CFsvc);
          }
          var dm:DataManagerCF= DataManagerCF.instanceMap[CFsvc];
          return dm;
        }
 
        public function makeRemoteCall(methodName:String,eventName:String,...args:Array):Void{
            this.eventName = eventName;
            var op:mx.rpc.AbstractOperation = CFsvc[methodName];
            CFsvc.addEventListener("result", doResults);
            CFsvc.addEventListener("fault", doFault);
            if(args.length >0){
                 op.send.apply(null,args);
            }  else {
                 op.send();
            }
        }
 
        private function doResults(result:ResultEvent):Void{
             var e:DataManagerResultEvent = new DataManagerResultEvent(eventName,result.result);
             this.dispatchEvent(e);
        }
 
        private function doFault(fault:FaultEvent){
             this.dispatchEvent(fault);
        }
 
        public override function toString():String{
             return "DataManagerCF";
        }
    }
 
  /**
   PrivateClass is used to make
   DataManager constructor private
  */
 
  private class PrivateClass{
        public function PrivateClass() {}
  }
}

 


I'll post more on this in the next few days as I get a chance to work with it.

tags:            

links: digg this    del.icio.us    technorati    reddit




1. AG left...
Tuesday, 31 October 2006 8:38 pm

Any more news on this, possibly a few examples of how to use it?


2. flexer left...
Wednesday, 27 June 2007 12:13 am

The styling for the code sample area is horrible, I had to copy and read somewhere else, the white on gray is just unreadable.


3. Bad Colors left...
Thursday, 13 March 2008 12:36 pm :: http://www.profeval.com

Thanks for writing this up...

However, the page colors need work... I can't read the code!