AMFPHP with ActionScript 3 101


1. Use to call server-side function this way:

var conn:NetConnection = new Connection();

conn.connect(;“com.projectA.ClassName.getCash”, new Responder(onResult, onFault), param1, param2);

In the call() function of Connection object, the first parameter is the method “identifier” of type String in the form of dot-delimited packagePath.className.methodName; the second parameter is a Responder object that takes two parameters with the first one onResult handler and the second one onFault handler (both takes one paramter of tyep Object); the rest/consecutive parameters are the parameters that are taken by the first remote method call.

2. Implement onFault() and onResult() for the remote method call. onFault() always take a type Object parameter against which you can still reflect by the old-good-day “for-property-in-object” style loop. onResult() takes the returned function call result from the remote method. It can be complex type such as Object or native AS3 dataTypes such as String or Array. A server-side defined class needs to have its corresponding AS class and is deserialized as “associative” array by onResult().

Below is a snippet AS of working example:

package test
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.system.System;
import flash.utils.describeType;
import packageName.ClassName;
public class AMFPHPTest01 extends Sprite
private var _foo:TextField;
private var gatewayURL:String = "";
private var connection:NetConnection;
public function AMFPHPTest01():void
private function inititialize():void
_foo = new TextField();
_foo.text ="info";
_foo.autoSize = TextFieldAutoSize.LEFT;
private function init():void
_foo.text = "TotalMemory: "+System.totalMemory;
connection = new NetConnection();
//connection.objectEncoding = ObjectEncoding.AMF0;
connection.connect(gatewayURL);"packageName.className.methodName", new Responder(onResult, onFault), 1);
private function onResult(evt:Object):void
_foo.text = "onResult!";
private function onFault(obj:Object):void
_foo.text = "onFault!\n"+"obj: "+obj.error;
description: The class {*} could not be found under the class path {*}
level: User Error
details: */BasicActions.php
line: 33
var description:XML = describeType(obj)
//will output an xml object
private function reflect(obj:Object)
for(var i in obj)
_foo.appendText("\n"+i+": "+obj[i]);
//trace(i+": "+obj[i]);


1. No need to define a method table to expose services to the gateway any more. Just declare those methods as public;

2. Use _explicitType as a class member to map a php class to an AS one like this in a php class definition.

"var $_explicitType = "packageName.ClassName“;

2 Responses to “AMFPHP with ActionScript 3 101”

  1. cyberprodigy Says:

    At the very beginging of post there is

    var conn:NetConnection = new Connection();

    but IMHO there should be

    var conn:NetConnection = new NetConnection();

  2. Jon Says:

    Just stumbled across this and it was exactly what I was looking for so thank you for posting!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: