在 Action Script 3 中访问 AMF 调用的响应程序对象
我是 AS3 的初学者,我使用 FlashDevelop 作为 IDE,并尝试连接到 AMF3 服务 (amfphp) 并获取用户详细信息。
我可以在 AMFinit() 函数中使用此代码连接到 AMF 服务...
private function AMFinit():void{
AMFService.objectEncoding = ObjectEncoding.AMF3;
AMFService.connect(AMFServiceURL);
AMFService.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var responder:Responder = new Responder(AMF_MyUserInfo, AMF_onFault);
AMFService.call("Danisman.GetUserWithIdentifier", responder, user_identifier);
// I NEED TO USE returned object data here!!
}
在 AMF_MyUserInfo() 函数上,我可以获取从响应程序返回的对象,并且可以成功跟踪它,这是代码
private function AMF_MyUserInfo(res:Object):void {
AMF_onResult(res);
trace(res.user_ID + res.username);
}
但是要在 AMF_MyUserInfo() 函数之外使用我想要将该“res”对象复制到另一个对象。我尝试在 Class 中指定一个对象,并使用“this.myobject = res”在 AMF_MyuserInfo() 函数中将 res 设置为该对象,但它不起作用。我也尝试过“this.myobject.username = res.username”,但它也不起作用。
我是 OOP 新手,如何在全局或 AMFinit() 函数中使用此 res 对象?
感谢您的帮助...
I'm beginner to AS3 and I'm using FlashDevelop as IDE and I'm trying to connect to AMF3 service (amfphp) and get user details.
I can connect to AMF service with this code in AMFinit() function...
private function AMFinit():void{
AMFService.objectEncoding = ObjectEncoding.AMF3;
AMFService.connect(AMFServiceURL);
AMFService.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var responder:Responder = new Responder(AMF_MyUserInfo, AMF_onFault);
AMFService.call("Danisman.GetUserWithIdentifier", responder, user_identifier);
// I NEED TO USE returned object data here!!
}
on AMF_MyUserInfo() function I can get object returned from Responder and I can trace it successfully, here is the code
private function AMF_MyUserInfo(res:Object):void {
AMF_onResult(res);
trace(res.user_ID + res.username);
}
But to use outside the AMF_MyUserInfo() function I want to copy that "res" object to another object. I tried with specifing an object in Class and set res to this object in AMF_MyuserInfo() function with "this.myobject = res" but it didn't work. I also tried "this.myobject.username = res.username" but it didn't work also.
I'm newbie to OOP, how can I use this res object globally or in AMFinit() function?
Thanks for your help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以跟踪函数中的
res
值,那么一切都应该没问题。无法说出可能出了什么问题。不过我对 AMF 服务不熟悉。因此无法告诉您它如何处理您的
res
对象。因为 AS3 中的对象会发生这种情况:如果您想全局使用任何属性,创建新类:
那么您可以像这样访问它们:
希望它会对您有所帮助。
if you can trace the
res
value in the function then everything should be ok. Can not tell what can be wrong.However i'm not familiar with AMF services. So can not tell you how it handles your
res
object. Because this what is happeing with objects in AS3:If you want to use any property globaly create new class:
Then you can access them like this:
hope it will help you a bit.