AMFPHP and actionscript 3
Saturday, October 13th, 2007I am writing an online multiplayer card game that uses AMFPHP and Flash actionscript 9. Here goes the code that connects Actionscript 3 with AMFPHP. I am writing it step wise so that it may help beginners.
1) Step no 1
develop a service class in PHP and place the class at the services folder of the AMFPHP
my code goes here
=======games/Gameservice.php========
class GameService
{
function getVersion()
{
return “1.1″;
}
function getArrayWithParameter($a,$b)
{
$arr=array();
$arr[0]=$a;
$arr[1]=$b;
$arr[2]=$a+$b;
return $arr;
}
}
2) Step no 2 In action script 3
var conn:NetConnection=new NetConnection();
var resultArray:Array;
var responder:Responder=new Responder(onResult,onError);
function onResult(arr:Array)
{
resultArray=arr;
test();
}
function onError(err:Error)
{
trace(err.description);
}
conn.connect(”http://localhost/amfphp/gateway.php”);
conn.call(”games.Gameservice.getArrayWithParameter”,responder,12,122);
//here 12 and 122 are the arguments
function test()
{
trace(resultArray[3]);
//output is 134
}
}