The Flash remoting allows to easily transfer complex data between ActionScript code running in a flash movie, and PHP code running on a webserver, in both directions.
In other words, it lets you to call (from ActionScript) PHP functions defined in files on a webserver as if they were defined in your ActionScript code.
You will need two files for this: a PHP file,
helloService.php, and a flash movie.
The
helloService.php should be placed in the
services directory (which is located at the same level as the
gateway folder).
Contents of the php source file:
<?
function helloMethod($param1){
return "Hello ".$param1;
}
?>
The ActionScript code:
#include "Cabron.as"
#include "CabronDebugger.as"
_global.cc = new CabronConnector();
cc.setGatewayURL("http://your.server.com/cabronconnector/gateway");
function helloMethod_Result(res){
trace("Response:" + res);
}
function helloMethod_Status(errMsg, errCode, shortErrMsg){
trace("Error occured:" + errMsg);
}
var helloService = cc.getService("helloService",this);
helloService.helloMethod("World!");
The Cabron Connector does not use the AMF to transfer the data, it uses the LoadVars ActionScript object. So the data is transmitted as a regular POST, after it is serialzied in the CDE (Compact Data Exchange) format.
CDE is a proprietary text-based format, which tries to minimize the size of the data needed for representing a given structure, and it facilitates timed deserialization.
This can be useful when transferring huge amount of data from the PHP services to Flash. Because the LoadVars works in the main thread of Flash, the deserialization happens in the main thread, blocking the Flash movie. This can lead to:
- The blocking of the main movie: the graphical elements won't animate for a while, and the interface does not respond to user events - this is the better case
- The "A script in this movie is causing Flash Player to run slowly..." message can appear. This is the worse case.
To avoid these nasty situations, you can set the deserialization to be performed not on a single frame, but in a sequence of frames. This way the flash movie won't block, but of course there will be a difference between the frame when the data is loaded to Flash, and the frame when the data is deserialized and the
Result handler is called.