How to set up and get WebOrb communication with Flex 2 with no service-config.xml
October 1st, 2007
So at work we are experimenting with WebOrb to ditch XML. No for good but definatly when there will be a lot of parsing. Anyway, our PHP Programmer downloaded WebOrb and we looked at the examples but the example were either banking on you having previous Flex Data Services experience or they were not that good in my opinion. The most crucial info was not even on the tutorial application page. So I’m going to walk you through the tutorial with the modification I used to get it working from various Google Searches. Mainly no service-cofig.xml.
- Ok, first thing is go to WebOrb’s website http://www.themidnightcoders.com/weborb/php/index.htm
I’m using the PHP version, and make sure you have PHP5. - Upload it to your server on put it in you localhost folder. We have it in a folder called “WebOrb” (http://YOUR_SITE/WebOrb)
- Create a new project in Flex.
- Go to the WebOrb tutorial. http://www.themidnightcoders.com/weborb/php/gettingstarted.htm skip down to the heading CONFIGURATION – FLEX BUILDER follow those directions. The remote config on our set up is http://YOUR_SITE/WebOrb/Weborb/WEB-INF/flex/remote-config.xml The last direction on the site is the server code (PHP) that goes in the Services folder located in http://YOUR_SITE/WebOrb/Services/InfoServices (with our current set-up)
- Now let’s go to another page and get the info on how this is connection to the service because that tutorial told me nothing about service-cofig.xml. Invoking PHP objects w/ Remote Object.
- don’t worry about this skip it (if you do worry go to the remote-config.xml to check it out http://YOUR_SITE/WebOrb/Weborb/flex):< <destination id=”destination-name”>
<properties>
<source>Your.PHP.ClassName</source>
</properties>
</destination>we will be using a GenericDestination which is already in the remote-config.xml:<destination id=”GenericDestination”>
<properties>
<source>*</source>
</properties>
</destination>
the source tag will be filled in the Flex code. - now we will fill out the mxml RemoteObject:
< mx:RemoteObject id="InfoServiceObj" destination="GenericDestination" endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showbusycursor="true" fault="onFault(event)"> < mx:method name="getComputerInfo" result="onResult(event)"> mx:RemoteObject> endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" and destination="GenericDestination" are what make this RemoteObject flexible. All you have to do is change you destination and your ready to go for another service. Endpoint is like you gateway in AMFPHP (to all the classes of weborb)
- Lastly here are the handlers for the modified example.mxml, dump this in over the old scripts
import mx.rpc.remoting.*; import mx.controls.*; import mx.rpc.events.* public function onCreationComplete():void { InfoServiceObj.getComputerInfo.addEventListener("result", onResult); } public static function onFault(event:FaultEvent):void { Alert.show(event.fault.faultString, 'Error'); } private function onResult(event:ResultEvent):void { var computerInfo:Object = event.result; currentUserText.text = computerInfo.currentUser; processIdText.text = computerInfo.phpProcessId; osText.text = computerInfo.operatingSystem; phpVersionText.text = computerInfo.phpVersion; invokeButton.enabled = true; } private function getInfo():void { invokeButton.enabled = false; currentUserText.text = ""; processIdText.text = ""; osText.text = ""; phpVersionText.text = ""; InfoServiceObj.getComputerInfo(); } and put a click handler on the button click="getInfo()"
here is the code I hope it helps:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.rpc.remoting.*;
import mx.controls.*;
import mx.rpc.events.*
public function onCreationComplete():void
{
InfoServiceObj.getComputerInfo.addEventListener("result", onResult);
}
public static function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, 'Error');
}
private function onResult(event:ResultEvent):void
{
var computerInfo:Object = event.result;
currentUserText.text = computerInfo.currentUser;
processIdText.text = computerInfo.phpProcessId;
osText.text = computerInfo.operatingSystem;
phpVersionText.text = computerInfo.phpVersion;
invokeButton.enabled = true;
}
private function getInfo():void
{
invokeButton.enabled = false;
currentUserText.text = "";
processIdText.text = "";
osText.text = "";
phpVersionText.text = "";
InfoServiceObj.getComputerInfo();
}
]]>
</mx:Script>
<mx:RemoteObject destination="GenericDestination" source="InfoService" id="InfoServiceObj" endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showBusyCursor="true">
<mx:method name="getComputerInfo" result="onResult(event)" />
</mx:RemoteObject>
<mx:Panel x="10" y="10" width="329" height="189" layout="absolute" title="Info Service Example">
<mx:Label x="10" y="10" text="Current user:"/>
<mx:Label x="10" y="36" text="PHP Process ID:"/>
<mx:Label x="10" y="62" text="OS/Architecture:"/>
<mx:Label x="10" y="88" text="PHP Version:"/>
<mx:TextInput x="113" y="8" width="186" editable="false" id="currentUserText"/>
<mx:TextInput x="113" y="34" width="186" editable="false" id="processIdText"/>
<mx:TextInput x="113" y="60" width="186" editable="false" id="osText"/>
<mx:TextInput x="113" y="86" width="186" editable="false" id="phpVersionText"/>
<mx:Button id="invokeButton" x="166" y="116" label="Get Computer Info" click="getInfo()" />
</mx:Panel>
</mx:Application>
Last 5 posts in AMF
Last 5 posts in as3
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Guitar Synth for Flash - February 27th, 2009
- Abstract Thermometer AIR app - January 22nd, 2009
- Roman Numeral/Arabic Convertion AIR App - Johnny V Now Available - December 25th, 2008
- How to convert Roman Numerals and Arabic numbers in ActionScript 3 - December 17th, 2008
Last 5 posts in flash
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Roman Numeral/Arabic Convertion AIR App - Johnny V Now Available - December 25th, 2008
- How to convert Roman Numerals and Arabic numbers in ActionScript 3 - December 17th, 2008
- Flash Player 10 Pure Flash Keyboard using SampleDataEvent - September 3rd, 2008
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
Last 5 posts in Flex
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Adobe Evangelist Daniel Dura visits Travelocity - April 15th, 2008
- Yahoo Maps ActionScript 3.0 Released - February 11th, 2008
- Papervision 3D 2.0 / Great White Example - December 26th, 2007
- Tidbit #3 - testing additions to your code - Control Variable - November 28th, 2007
2 Comments Add your own
1. JD17 | February 13th, 2008 at 5:13 pm
Hi,
Did you manage to get the secure part working?
Any chance you could do a quick writeup if you did???
I would like to know how to be able to do a quick login using mysql credentials and not allow access to the services (classes) unless the user is logged in/has rights.
2. joshspoon | February 13th, 2008 at 10:46 pm
I haven’t messed with security. Sorry
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed