AMFPHP 1.0 Works with Flex 2 / Flash Player 8.5 Alpha

Thanks to Patrick Mineault, Renaun Erickson, Dave Wolf, and Peter Farland.

To get AMFPHP to work with the Flex 2 Alpha, you need to:

  1. Extend NetConnection just so 3 methods can be added to it
  2. Have your gateway connection extend that new class
  3. Have the new encoding set to AMF0
  4. Make your calls using “YourClassAndPackage.method”

The extended NetConnection looks exactly like this:

        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 your custom class
import NetConnection2;

public var gateway_conn:NetConnection2;
// setup your jazz
var gatewayURL:String = "";
gateway_conn = new NetConnection2();
gateway_conn.objectEncoding = ObjectEncoding.AMF0;
// 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);"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…

19 Replies to “AMFPHP 1.0 Works with Flex 2 / Flash Player 8.5 Alpha”

  1. I did the same thing about a month ago but also including auto converting resultset from php to arraycollection, then bind to whatever controls i want :-)

    actually you just need to create a dummy AppendToGatewayUrl() method then everything else would work.

  2. Jesse.

    Thanks for the info. I’ve been hangin to get remoting and flex2 talking…

    small error in your e.g. – the second callback function should be:

    public function onPingStatus(fault:Object):Void


    public function onPingResult(fault:Object):Void

  3. I’m a bit new to all this flex stuff any chance of an example app to demonstrate how you implement this gear? That would rock.

  4. Hey Andy, here’s a Flex 1.5 & Flash MX 2004 set of examples. Flex 1.5 and Flex 2 syntactically are very similiar. There only difference is my example code here doesn’t use the RemoteObject tag (which is a wrapper for some of the remoting code among other things).

  5. With flex 2 beta :
    i implemented your solution with amfphp and it works; but if I return the result of mysql_query($query) , the dataProvider for a DataGrid doens’t work . (works fine if I retun an array).
    This solution works fine in flash MX 8 : problem seems come from Recordset and _items …
    Any idea ?

  6. Go here:

    C:\Documents and Settings\Syle\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes\mx\remoting

    And convert the file to AS3. I don’t know what is involed in converting the remoting code though to make it parse to this; maybe one othe classes in there does it.

  7. don’t go the long way to port recordset to AS3, use mx.collections.ArrayCollection instead.

    you just need a loop to combine column names and data value from amfphp result to Array then wrap it in an ArrayCollection.

  8. Has anyone been successful in getting a specific class returned using this technique? I am now using registerClassAlias instead of the old ojbect.registerClass, but no matter what, it comes back from the remote service as a generic object instead of my specific class. Is it working for anyone else, letting me know its hopefully something in my code, or is it a bug/limitation in Flex Beta 1?


  9. thanx,

    It helped me a lot………………..

    Morething, i m eager to know how AMFPHP works with Flex-2 beta +FES-2……..



  10. Jesse,

    I am bit confused with the above code.its not working for me

    can u pls clarify me what will be exectly ‘your phpclass.the methode….in below code
    var r:Responder = new Responder(onPingResult, onPingStatus);‘YourPHPClass.theMethod’, r);


  11. Hi there,

    anyone got an idea how to give a query from Flex 2 to an AMFPHP method? I did this with flash 8 and amfphp but have problems with flex 2 and amfphp. Do I have to use AJAX or is there another way?

    Regards Freddy

Comments are closed.