在 Action Script 3 中访问 AMF 调用的响应程序对象

发布于 2024-11-07 15:33:13 字数 1039 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂柯人 2024-11-14 15:33:13

如果您可以跟踪函数中的 res 值,那么一切都应该没问题。无法说出可能出了什么问题。

不过我对 AMF 服务不熟悉。因此无法告诉您它如何处理您的 res 对象。因为 AS3 中的对象会发生这种情况:

var startObject : Object;
var dublicate : Object;

startObject = new Object ();   // creating new object
startObject.userID = 'myname'; // setting some parameters there

dublicate = startObject;       // referencing you dublicate to the startObject
startObject.userID = null;     // changeing startObject property
trace ( dublicate.userID );    // dublicate is also affected ( output: null )

// another example
startObject = new Object ();   // creating new object
startObject.userID = 'myname'; // setting some parameters there

dublicate = new Object ();     // creating new dublicate object
dublicate.userID = startObject.userID; // setting the dublicate parameter
                                       // with start Object parameter

startObject.userID = null;     // changing startObject property
trace ( dublicate.userID );    // dublicate is not affected, because it is not
                               // a reference but independant object.
                               // ( output: myname)

如果您想全局使用任何属性,创建新类:

package
{
    public class GlobalVariables
    {
        static public var userName : String;
        static public var userID : String;
    }
}

那么您可以像这样访问它们:

GlobalVariables.userName

希望它会对您有所帮助。

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:

var startObject : Object;
var dublicate : Object;

startObject = new Object ();   // creating new object
startObject.userID = 'myname'; // setting some parameters there

dublicate = startObject;       // referencing you dublicate to the startObject
startObject.userID = null;     // changeing startObject property
trace ( dublicate.userID );    // dublicate is also affected ( output: null )

// another example
startObject = new Object ();   // creating new object
startObject.userID = 'myname'; // setting some parameters there

dublicate = new Object ();     // creating new dublicate object
dublicate.userID = startObject.userID; // setting the dublicate parameter
                                       // with start Object parameter

startObject.userID = null;     // changing startObject property
trace ( dublicate.userID );    // dublicate is not affected, because it is not
                               // a reference but independant object.
                               // ( output: myname)

If you want to use any property globaly create new class:

package
{
    public class GlobalVariables
    {
        static public var userName : String;
        static public var userID : String;
    }
}

Then you can access them like this:

GlobalVariables.userName

hope it will help you a bit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文