Skip to main content

Dynamic RemoteObject defined by settings in an XML file

In my CF United 2008 presentation on Charting with Flex and ColdFusion, I demonstrated a nifty actionscript function to dynamically create a remoteObject without needing to use services-config.xml. (The code is nearly identical to code written by Mike Nimer, but lovingly frosted with glucose... rr tweaked for my needs) I also mentioned that using this, it would be possible to have an external settings file read at runtime that defined your remote object endpoint, without needing to use an annoying services-config.xml file and allowing run-time configuration of your remote data services.

Why would you want to do that? (you might ask...) Well, the short answer is that you can re-configure the server that your app talks to without re-compiling your flex app, which is really important if you do any type of QA testing.

So this post is all about how to do that thing i just described.To start, lets create a settings.xml file in the root of our source. Lets say it looks like this:


Here is the main app code, and then I will explain:

So here is how this works. When the flex app finishes loading, it will call onCreationComplete(), which tells the http service to load the settings.xml file. When the http service completes, it calls handleLoadSettings(), which parses the settings.xml file and pulls out our values into local private vars, and then calls the configRemoteObject() function to build the dynamic remote object.

At this point, you use your remote object from actionscript, simply remembering to add any event handlers you want before invoking a function name, so for example "callMyRpc()" where "myRpc" is a function in the cfc you specified in your settings.xml file (the cfc setting of course, which is the dotted path to your CFC, but without the ".cfc" on the end).

As long as you add event handlers, you can define and call as many functions on that CFC as you want. If you want to call against a different CFC, then create a new RemoteObject using the same method.

Hope this helps many Flex Coders to break free from services-config.xml!

Popular posts from this blog

Installing python 3.4.x on OSX El Capitan

I love "brew" package manager, but sometimes being too progressive breaks things.  I have several python apps that I maintain that get deployed to AWS using Elastic Beanstalk.  AWS eb can deploy with python 2.7 or 3.4.  Any recent 'brew install python3" will get 3.5.1. #annoying

Making Macbook Air with 128GB SSD usable with Bootcamp

I recently got a new Macbook Air 11" (the 2012 version) and loaded it with goodies like 8GB ram and 2GHz Core i7.  What I DIDN'T upgrade was the internal SSD.  My config came with 128GB SSD and I refused to pay $300+ to upgrade it to 256GB.  Yeah I know, some call me cheap, but SSds cost $75-$150 for 240GB, so adding another 128GB for $300 seemed way too steep for me.  I figured "ok, I'm going to make 128G work!"

Here is the story of how that went...

Getting Started with OpenVAS on CentOS - an open source vulnerability scanner

The Open Vulnerability Assessment System (OpenVAS) is a framework of several services and tools offering a comprehensive and powerful vulnerability scanning and vulnerability management solution. (Taken from the OpenVAS website, which is at )

This blog entry will introduce OpenVAS version 3.1, walk through installation on CentOS and is intended as a "getting started" guide. I'll also do a guide for installing on Ubuntu later.