Thanks to Patrick Mineault, Renaun Erickson, Dave Wolf, and Peter Farland.
To get AMFPHP to work with the Flex 2 Alpha, you need to:
- Extend NetConnection just so 3 methods can be added to it
- Have your gateway connection extend that new class
- Have the new encoding set to AMF0
- Make your calls using “YourClassAndPackage.method”
The extended NetConnection looks exactly like this:
package { import flash.net.NetConnection; public class NetConnection2 extends NetConnection { public function AppendToGatewayUrl(append:String):Void { } public function AddHeader():Void { } public function ReplaceGatewayUrl():Void { } } }
And some psuedo code for calling your server:
// import the internal classes import flash.net.Responder; import flash.net.NetConnection; import flash.net.ObjectEncoding; // import your custom class import NetConnection2; public var gateway_conn:NetConnection2;
// setup your jazz var gatewayURL:String = "http://server.com/amfphpfolder/gateway.php"; gateway_conn = new NetConnection2(); gateway_conn.objectEncoding = ObjectEncoding.AMF0; gateway_conn.connect(gatewayURL);
// call back functions public function onPingResult(event:Object):Void { // success! } public function onPingResult(fault:Object):Void { // loop through fault object }
// make a method call on // a PHP class var r:Responder = new Responder(onPingResult, onPingStatus); gateway_conn.call("YourPHPClass.theMethod", r);
You can pass as many parameters you want starting from the 3rd parameter, on.
Bad news is, mx.remoting.RecordSet converted recordsets for you in Flash MX 2004 & Flash 8. Since that class doesn’t exist in Flex 2, you can either wait for Adobe to do it, do it yourself, or convert plain arrays to meaningful data.
Remoting with strong-typing… mmmmmm…