使用 PHP 解码 amf3 对象
我的 Flash 代码:
var request=new URLRequest('http://localhost/test.php');
request.method = URLRequestMethod.POST;
var data = new URLVariables();
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF3;
//write an object into the bytearray
bytes.writeObject(
{ myString:"Hello World"}
);
data.data = bytes;
request.data = data;
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
urlLoader.load(request);
function onCompleteHandler(evt:Event):void {
trace(evt.target.data);
}
PHP 代码:
define("AMF_AMF3",1);
$data = $_POST['data'];
echo amf_decode($data, AMF_AMF3);
基本上我需要将 AMF3 对象从 Flash 发送到 PHP 并对其进行反序列化。我正在使用 AMFEXT 扩展,但无法让它工作。有什么想法吗?
My flash code:
var request=new URLRequest('http://localhost/test.php');
request.method = URLRequestMethod.POST;
var data = new URLVariables();
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF3;
//write an object into the bytearray
bytes.writeObject(
{ myString:"Hello World"}
);
data.data = bytes;
request.data = data;
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, onCompleteHandler);
urlLoader.load(request);
function onCompleteHandler(evt:Event):void {
trace(evt.target.data);
}
PHP code:
define("AMF_AMF3",1);
$data = $_POST['data'];
echo amf_decode($data, AMF_AMF3);
Basically I need to send an AMF3 object from Flash to PHP and unserialize it. I'm using AMFEXT extension but couldn't get it to work. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试这个 - http://sourceforge.net/projects/php-amf3/
You can try this one - http://sourceforge.net/projects/php-amf3/
我用 PHP 为我的项目 FlashMOG 编写了一个简单的 AMF3 序列化器/反序列化:
此处
需要进行一些调整。
I wrote a simple AMF3 Serializer/Deserialize in PHP for my project FlashMOG:
here
It would need a bit of adaptation.
您是否看过 AMFPHP:http://www.amfphp.org/
“AMFPHP 是免费的操作消息格式 (AMF) 的开源 PHP 实现允许将操作脚本(AS2、AS3)本机类型和对象的二进制序列化发送到服务器端服务。AMFPHP 面临着实现整个 AMF 协议的挑战。 Flex Data Services (AMF3) 和 Flash Remoting (AMF0) 的替代方案”
Have you had a look at AMFPHP: http://www.amfphp.org/
"AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services. AMFPHP is challenged with implementing the entire AMF protocol to be an alternative to Flex Data Services (AMF3) and Flash Remoting (AMF0)"
看看AMFPHP项目,我在一个聊天项目上使用了它,它确实使用简单且高效。
just take a look at the AMFPHP project, I used it on a chat project and it is really simple to use and efficient.