|
Resources
Tutorials, External Links, Code Samples
DocumentationEach RPC type is based on a AbstractRPCObject which mimics the native http://livedocs.macromedia.com/flex/2/langref/. Since the implementation is the same for the different RPC types (AMF0,XML-RPC and JSON-RPC), AbstractObject will be used to generalize them in the examples. Simply replace <ak33m:AbstractObject> with the appropriate tags:
General Example: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ak33m="http://ak33m.com/mxml" creationComplete="callFunction();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
function callFunction ()
{
//sample method call using token pattern
someapi.doSomeThing(param1,param2);
//sample method call if method has a dot (.) (as is the case with blog xmlrpc API
someapi.call("method.with.dot",param1,param2);
}
]]>
</mx:Script>
<ak33m:AbstractObject id="someapi" endpoint="http://ak33m.com" destination="someendpoint" fault="Alert.show(event.fault.faultString,event.fault.faultCode)">
</ak33m:AbstractObject>
</mx:Application>Below is an example using the xmlrpc api of a blog. It uses the token pattern and the ItemResponder. NB Any class that implements IResponder can be used. ItemResponder is the only responder natively available in Flex 2© and hence utilized in this example <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ak33m="http://ak33m.com/mxml" creationComplete="">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.AsyncToken;
import mx.controls.Alert;
import mx.collections.ItemResponder;
var urlregexp:String = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";
var endpointregexp:String = "/[A-Za-z0-9-_%&\?\/.=]";
function login ()
{
//This is the rpc call. Because the xmlrpc service used in this example has functions with dots (.) in them the call function is used
//if there was no dot the call could be blogapi.getUserInfo ()
var token:AsyncToken = blogapi.call("blogger.getUserInfo","",user_txt.text,password_txt.text);
var tresponder:ItemResponder = new ItemResponder(this.showUserInfo,this.onFault);
token.addResponder(tresponder);
}
function showUserInfo (event:ResultEvent,token = null)
{
Alert.show("User: "+event.result.nickname,"User info result");
}
function onFault (event:FaultEvent, token=null)
{
Alert.show(event.fault.faultString,event.fault.faultCode);
}
]]>
</mx:Script>
<!-- Validation -->
<mx:RegExpValidator id="regExpV"
source="{rooturl_txt}" property="text"
flags="g" expression="{urlregexp}" noMatchError="Please enter a valid URL"
/>
<mx:RegExpValidator id="endpointregExpV"
source="{this.endpoint_txt}" property="text"
flags="g" expression="{endpointregexp}" noMatchError="Please enter a valid endpoint. It MUST start with a /"
/>
<!-- User Interface -->
<mx:Panel height="300" width="380">
<mx:Form height="200" width="350" x="0" y="0">
<mx:FormHeading label="Blog Login" textAlign="left"/>
<mx:FormItem label="Root URL">
<mx:TextInput id="rooturl_txt"/>
</mx:FormItem>
<mx:FormItem label="Xmlrpc endpoint">
<mx:TextInput id="endpoint_txt"/>
</mx:FormItem>
<mx:FormItem label="Username">
<mx:TextInput id="user_txt"/>
</mx:FormItem>
<mx:FormItem label="Password">
<mx:TextInput id="password_txt"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Send" id="send_btn" click="login();"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
<!-- RPC Object -->
<ak33m:XMLRPCObject id="blogapi" endpoint="{rooturl_txt.text}" destination="{endpoint_txt.text}" >
</ak33m:XMLRPCObject>
</mx:Application>External LinksSpecifications |
Sign in to add a comment

How to add this to a Cairngorm delegate :(
How to add this to a Cairngorm delegate :(
df
Can you post example code of calling a method of a service class using AMFPHP? Thank you!!!
I noticed that the final .swc file was 440K+. Is there anyway to make it smaller? I only was using the xmlrpc code so I didn't link the json and amf code, but that only reduced the size by ~10K.
@tommyw13 the file size could be attributed to the use of HTTPService code. I will look at file size options in future releases.
@dorkiedorkfromdorktown the use of of AMFPHP should be the same as using the xml-rpc piece, only difference being the use of AMF0Object instead of XMLRPCObject
In a Cairngorm delegate, how do I reference my XMLRPCObject? I've tried it as such:
import com.adobe.cairngorm.business.ServiceLocator; ... service = ServiceLocator.getInstance().getHTTPService("loadDataService");
But ServiceLocator?? only has getHTTPService, getWebService, and getRemoteObject functions. How do I reference this XMLRPCObject?
In MXML, I have it defined the object as:
<ak33m:XMLRPCObject id="loadDataService" endpoint="http://localhost:8080"/>
Thanks!
Never mind, I figured it out. ServiceLocator? also has a generic getService() function, which works with XMLRPCObject:
service = ServiceLocator.getInstance().getService("loadDataService");
Hi, I get a security error when I try and use this to access the XMLRPC service on Livejournal.com. After reading up it seems that SWFs are not allowed to make connections to URLs that the SWF wasn't loaded from without some special setup on the remote server (which won't happen in my case) or by using a proxy.
Any recommendations on how to do this with your library?
Thanks in advance.
In regard to filesize, and the use of the less than reliable HTTPService, you could always use the as3httpclient package, by Abdul Qabiz. It's an HTTP client written entirely in AS3, and hosted here on google code: http://code.google.com/p/as3httpclient/
While only the SVN version seems to be up to date, it does seem to work well from my (admittedly limited) testing.
Hello, my HTTP headers show that I am sending a Content-Type of application/xml. Is there a way in your library to send Content-Type of text/xml instead? It is required for the service I am trying to access, and I did not find it in the documentation.
Thank you
@elliott.hoffman the build that is in svn has the correct content type header. Its been a while since I updated the featured download. For the latest and greatest get the swc that is in svn
@evan thanks. I'll check it out. I have been meaning to get rid of the HTTPService use but so little time.
I'm getting a "Illegal Override of XMLRPCObject" when I do something as simple as this:
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication? xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:ak33m="http://ak33m.com/mxml"> <ak33m:XMLRPCObject id="server" endpoint="http://localhost:7080"/> </mx:WindowedApplication?>
I don't get the error message with earlier versions.
@BruceTEckel I've been unable to replicate this issue. Changes occured in the XMLRPCSerializer and I am not sure where that error would even stem from. Are you trying to swap the new version of the library out in an existing project?
We justed started using the latest release of as3-rpclib and we are getting the same error as Bruce ("Illegal Override of XMLRPCObject"). The errors are coming from two functions in 'XMLRPCObject.as'. Flex error panel is saying that the functions - 'setCredentials' & 'setRemoteCredentials' are "Overriding a function that is not marked for override".
Are the older versions of as3_rpclib available for download?
Looking for flex support for json-rpc. Is this supported and if so, what version did you target? Thanks. david
For people who are using Flex Builder 3, and have the "Illegal Override of XMLRPCObject" error, you need to:
1) import the project into flex builder 3
2) it'll tell you that the project was made in previous version of flex builder. Select the "default" version (which is Flex 3)
3) Open up XMLObject.as, look for "setCredentials" and replace the function signature with: override public function setCredentials (username:String,password:String,charset:String = null):void
4) right below, find "setRemoteCredentials" and replace the function signature with: override public function setRemoteCredentials (username:String,password:String,charset:String = null):void
5) build it (automatically) and enjoy!
@dshe yes older versions are available for download on the download page. Just change the drop down on the download page to Deprecated or All Dowloads. The error seems to be stemming from Flex 3 incompatibility (which I don't have :( )
@jamesyjhu thanks for offering the fix. I am unable to a Flex 3 build because I don't have it. If you can provide a Flex 3 build of the library so I can put it up on the downloads page that would be great. Thanks in advance
Hitting your xml name space isn't working. In FB3 I'm getting "Could not resolve <ak33m:XMLRPCObject> to a component implementation".
Good work! It seems that XMLRPCSerialize encodeString does not work well if the string contains special characters like '<', it needs to be escaped somehow.
I have to confirm issue with namespace -- "Could not resolve <ak33m:XMLRPCObject> to a component implementation"
Can you post example code of connect and call server methods for FMS3? Thank you.
Solution without .swc file
1. put the namespace for example > xmlns:ak33m="com.ak33m.rpc.xmlrpc." < in Application
2. in the root of your project put > com/ak33m/rpc/xmlrpc + files under it < structure
3. now you can instantiate <ak33m:XMLRPCObject>
Matko Kvesic
For people who are using Flex SDK 3, and have the "Illegal Override of XMLRPCObject" error, you need to:
1) Open up XMLRPCObject.as, look for "setCredentials" and replace the function signature with: override public function setCredentials (username:String,password:String,charset:String = null):void
2) In the same file, find "setRemoteCredentials" and replace the function signature with: override public function setRemoteCredentials (username:String,password:String,charset:String = null):void
3) Rebuild as3-rpclib.swc library, for example on Windows:
d:\flex\bin\compc.exe -source-path .\src -namespace http://ak33m.com/mxml .\src\manifest.xml -include-namespaces http://ak33m.com/mxml -output=.\bin\as3-rpclib.swc
Does anyone know if it's possible to automatically cast a value returned from an XML-RPC method to a particular datatype, for example a Value Object? Say for example I've called a method which returns an array of messageboard posts, and I have a Value Object class which represents a messageboard post, is there any way to automatically connect the two? How things stand, I'm receiving an array of Objects.
Currently, I'm iterating through the result array and creating each messageboard post manually, setting each and every property manually based on values in the current Object, but it feels like there should be a nicer way of achieving this.
Any ideas? Cheers, toby
Can anyone show an example of how I would use this in a flash cs3 project using the json? I think this is the only thing out there but am not sure how to use this thing?