Steps:
- Download Zend amf library and put it into your htdocs (www root) folder.
- Create a Gateway.php for connection
- Create your service using php
- Connect to service using ActionScript in TestService.fla
- Run the TestService.fla
Step 1:
- Download Zend amf library: http://framework.zend.com/download/amf
- Unzip and put the Zend folder into your htdocs folder
Step 2:
- Create a folder named “service” under htdocs.
- Create a Gateway.php under htdocs.
- Gateway.php:
<?php
require('./Zend/Amf/Server.php');//require('./services/HowAreYou.php');
$server = new Zend_Amf_Server();$server->addDirectory(dirname(__FILE__) .'/services/');//$server->setClass('HowAreYou');
$response = $server->handle();echo $response;?>
Step 3:
- Create your remote service “HowAreYou.php” under “service” folder
- HowAreYou.php
<?php
class HowAreYou{/*
* @param string $receiveMsg* @return string $replyMsg*/function sendStr($yourname){return "$yourname, 你好!";}}?>
Step 4:
- Write ActionScript in your TestService.fla file
- In TestService.fla
stop();var connection:NetConnection; // Initialize NetConnection Object
var responder:Responder; // Initialize Responder Object
//Construct Instance
responder = new Responder(onResult, onFault); // Show Receive Data
connection = new NetConnection;// Setting
var gateway:String = "http://localhost/Gateway.php";
connection.connect(gateway); // Connect to Zend amf
// Data Receieve
function onResult(Result:String):void {trace(Result);}// Fail
function onFault():void {trace("Connection Fail");
}// Call Remoting Service's Method: (Class.Method, reaonder, parameter)
connection.call("HowAreYou.sendStr",responder,"your_message");
Step 5:
- Test(Run) your TestService.fla
- you will receive “your_message,你好!” on the output window