Welcome!

Adobe News Desk

Subscribe to Adobe News Desk: eMailAlertsEmail Alerts
Get Adobe News Desk via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: ColdFusion on Ulitzer

CFDJ: Article

Creating a Remote Object DataManager in ActionScript 3.0 for Flex 2.0

Tien Nguyen followed up on my WebService DataManager with one for RemoteObject as well

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.

posted Wednesday, 4 January 2006
tags:          

More Stories By Adobe News Desk

MXDJ News Desk gathers stories, analysis, and information from around the world of software design and development and synthesizes them into an easy to digest format for MX developers.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
MXDJ News Desk 01/04/06 05:02:01 PM EST

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.