Search code examples
flashactionscript-3oopremoting

Accessing Responder Object for AMF Call in Action Script 3


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...


Solution

  • 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.