After doing some testing with Flash 8 / Flash 9 / Flex 2. I’ve found that there are three situations needed when handling result sets from a database and transforming them into their respective flash types.
With flash 8, mx.remoting.RecordSet is always used – simple. With Flash 9; if you’re using NetConnections the AMF version varies depending on the parameters you send in the request (even if you specify objectEncoding as 3, it will use AMF0 for some data types). Which creates a slight hickup for Flash 9 recordsets. Keep reading.
Take this for example:
import org.rubyamf.remoting.ssr.*;
var service = new RemotingService('http://localhost:8024/gateway.rb','org.rubyamf.amf.TestObject', 3)
service.passObjectThrough([""],onresult,onfault);
This example makes the request as AMF0 even though I specify AMF3 to the NetConnection#objectEncoding property. Not a huge deal. AMF0 is slightly faster anyway. I don’t mind.
Now test this:
import org.rubyamf.remoting.ssr.*;
var service = new RemotingService('http://localhost:8024/gateway.rb','org.rubyamf.amf.TestObject', 3)
var x:XML = new XML('someXML');
service.passObjectThrough([x],onresult,onfault);
This service call sends AMF3 to the gateway. Thats fine too.
Now test this:
import org.rubyamf.remoting.ssr.*;
var service = new RemotingService('http://localhost:8024/gateway.rb','org.rubyamf.amf.TestObject', 3)
service.getMysqlResult([],onresult,onfault);
This service call uses AMF0 to get a mysql result. This created a problem in RubyAMF but not anymore. Because it’s AMF0, the response is being cast as an mx.remoting.RecordSet. Which in Flash 9 doesn’t work. What it should be is fl.data.DataProvider. So the fix is to specify in the gateway what type of RecordSet you want to use with Flash (being Flash 8 or 9).
There is no way to sniff it and figure it out programatically because the information I have about the request is the content-type of x-amf. So the only solution is to manually set that recordset format. So that being said. There is now a way to set that property, in each respective gateway for webrick|lighttpd|mongrel.
I’ve tested this with AMFPHP and it is the same problem. If no one minds I’d fix it in 1.9 beta 2. Patrick?
Flex messaging with the RemoteObject tag doesn’t create a problem as it is always AMF3 and I can sniff when it is flex messaging – triggering mx.collections.ArrayCollection to be used for the return type. No problem there.
So with Flash 9, when you get a result set, you use the DataProvider class to populate a datagrid like so:
import fl.data.DataProvider; mydg.dataProvider = new DataProvider(re.result);
With Flash 8, you still use RecordSet.
import mx.remoting.RecordSet; mydg.dataProvider = RecordSet(re.result);
But you need to specify what recordset format you’re using in the gateway.
If you’re using Flex 2 and Messaging you would use an ArrayCollection. This is handled by default, no change is needed in any gateways.
import mx.collections.ArrayCollection; mydg.dataProvider = ArrayCollection(re.result);
Note that with Flash 9 you have to actually create a new DataProvider instance and pass the results to it. With Flex 2 you can just cast the result into an ArrayCollection.
So, I’m not in any way saying there is a problem with NetConnection. It works as expected. But because most of the time with NetConnection the request will be AMF0 data, a special case has to be added to our remoting gateways to give Flash 9 a usable collection of objects to populate the DataProvider instance with.
As mentioned above, a fix in AMFPHP is needed so that returning mysql results work in Flash 9 using NetConnection. Not sure about any other remoting gateways. Give it a shot in yours if you’re developing one. If this somehow already work with AMFPHP, let me know.
RubyAMF-0.9.8 Will have this fix in it.


