Skip to main content

Adobe Flex: Specifying Remote Object End Point

Update September 2009:  (In Adobe Flex SDK 3.3 and older, there is a difference between mx.rpc.remoting.RemoteObject and mx.rpc.remoting.mxml.RemoteObject.  The first one does not have an endpoint parameter that is why you can't dynamically specify the endpoint using Actionscript.

That is why I use mx.rpc.remoting.mxml.RemoteObject.

But as of Adobe Flex SDK 3.4, you can now use endpoint parameter with mx.rpc.remoting.RemoteObject. )


This is the sample code I use to call a Remote Object in Actionscript rather than the usual Adobe Flex MXML tag.

There are some advantages to doing your code this way. Like you can specify the endpoint dynamically.

You will need this import statements.


import mx.events.CloseEvent;
import mx.collections.ArrayCollection;
import mx.utils.ArrayUtil;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.mxml.RemoteObject;

var clientrecs:ArrayCollection;
...


I use a one fault handler for all remote object calls in case a problem occurs.

private function faultHandler (event:FaultEvent):void {

      Alert.show(event.fault.faultString, 'Error');
} // faultHandler

This is a sample list function. In this case I am using AMFPHP. And of course my server side business objects are written in PHP.

private function listClients():void {

      var clientRO:RemoteObject = new RemoteObject();
     clientRO.endpoint = "amfphp/gateway.php";
     clientRO.source = "ClientObj" // PHP Object Name
    clientRO.destination = "amfphp";
    clientRO.listClients.addEventListener("result", listResult); // resutl handler
    clientRO.addEventListener("fault", faultHandler); // fault handler
    clientRO.listClients(cmbClientType.text); // call the service

}

A thing to remember. Your Remote Object source must be exactly the same as you have written in the Actionscript code. In this case its ClientObj. Remember this is case sensitive.

// Result Handlers
private function listResult(event:ResultEvent):void {

     clientrecs = new ArrayCollection(ArrayUtil.toArray(event.result));


}

Finally I pass the result to an Array Collection variable which I then bind to a DataGrid.

Goodluck.

Comments

Popular posts from this blog

LED Monitor Review: LG FLATRON E2041

My Old AOC CRT Monitor began to show signs of dying. It would occasionally black out for a few seconds. Sometimes lightning streaks  would run across the screen. I bought that monitor way back in 2006. It served me well for 5 years. It was very durable and AOC is a good brand. And so I had no choice but to buy myself a new monitor. I would have preferred another CRT Monitor but they were no longer available. Even the more recent LCD screens are being phased out in favor a the newer LED monitors. LG FLATRON E2041 (This was not my first choice but it was the next best thing available in the computer store I visited). 1600 X 900 Resolution (16:9 Aspect Ratio) Contrast Ratio: 5,000,000:1 Brightness: 250 Cd/m2 Dimensions W/Stand (WHD): 17.44" X 13.78" X 6.54" My Feedback This monitor comes with two connectors VGA and DVI. It comes with a CD that is supposed to contain the manual and monitor drivers. However, when you install the monitor driver contain...

GIMP: How to Enable Wacom Pen Tablet

If you are doing digital graphics in Gimp, whether painting or simply drawing, it is best to use a pen tablet. Wacom is a recognized brand when it comes to pen tablets. Gimp does support it but it is not enabled by default. How to Enable Pen Tablet Support 1. Launch Gimp using your pen tablet. Don't use the mouse to launch Gimp. If you do, Gimp won't detect it. 2. In the menu click Edit>Preference. 3. On the list click "Input Devices". 4. Click "Configure Extended Input Decives". Here is where Gimp gets weird. If you started Gimp for the first time using a mouse, it will say there are no available input device. But if you launched it using the pen tablet, you will see "Wacom Tablet Pressure Stylus" and "Wacom Tablet Eraser" . 5. Click the Close Button 6. Click "Save Input Device Settings Now" so that the pen tablet will still be supported when you launch Gimp next time.

The World is Yours

If you were ever a fan of Scarface, the 1983 film starring Al Pacino, you would remember the last scene. Tony was shot on the back by an assassin. He falls down from the balcony into a small pool in the lobby below. He floated face down in the water. Beside him a statue was shown carrying the inscription "The World is Yours". I'm sure most of you find that humorous inspite of the tragic ending. But why did I mention it? Today I was thinking about eCommerce and I can't help but be amazed at the possibilities available to us today. The world is truly ours but only if we got the imagination to seize it. I'm talking about how any individual can be in their pajamas in the comfort of their bedroom and yet be able to sell a product or a service to practically anyone anywhere in the world. All you need really is just a computer and an internet connection and then you are good to go. It is simply amazing especially if you can remember back in the early 1990...