Flash + AMFPHP是一個很好的組合。但是,有些情況下,由於各種原因,使用NetConnection的Flash Remoting不是正確的工具。羅布對這個偉大的職位前段時間:http://www.roboncode.com/articles/144AMFPHP:通過HTTP序列化Flash對象,無需網關
他還對如何提供AMF到一個http請求一個很好的例子,沒有POST和AMF請求包來調用的NetConnection發送功能,採用Zend_AMF 。
// Include the Zend Loader
include_once 'Zend/Loader.php';
// Tell the Zend Loader to autoload any classes we need
// from the Zend Framework AMF package
Zend_Loader::registerAutoload();
// Create a simple data structure
$data = array('message' => 'Hello, world!');
// Create an instance of an AMF Output Stream
$out = new Zend_Amf_Parse_OutputStream();
// We will serialize our content into AMF3 for this example
// You could alternatively serialize it as AMF0 for legacy
// Flash applications.
$s = new Zend_Amf_Parse_Amf3_Serializer($out);
$s->writeObject($data);
// Return the content (we have found the newline is needed
// in order to process the data correctly on the client side)
echo "\n" . $out->getStream();
我非常喜歡這種方法,並且非常喜歡用AMFPHP進行復制。爲什麼選擇AMFPHP? '最新'版本使用amf-ext(C PHP擴展)來序列化和反序列化數據。它比ZendAMF仍在使用的php方式快得多。
當然,我已經玩過AMFPHP,並嘗試構建必要的對象並使用Serializer類。我甚至得到了一個有效的AMF字符串,但真正的數據總是被一個'方法包'包裝,告訴接收方這是'Service.method'調用的答案。
那麼有沒有辦法在AMFPHP中直接序列化Flash對象,而不使用網關和方法包裝?
謝謝。