Hi folks I have a scoping user that I'm struggling to understand. I
can't seem to access UserData.userInfo at the application level
because my variable is not scoped correctly. HELP ME! Anyways, here is
my code:

-----------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" creationComplete="init()">
        
        <mx:Script>
                <![CDATA[
                        import com.UserDataRequest;
                        import com.UserData;
                        
                        private var request:UserDataRequest;
                         
                        private function init(): void
                        {
                                request = new UserDataRequest("data.xml");
                                trace(UserData.userInfo);
                        }
                ]]>
        </mx:Script>
        
                
</mx:Application>

UserDataRequest.as
------------------------------------------------------------------
package com
{
        import mx.rpc.http.HTTPService;
        import mx.rpc.events.ResultEvent;
        import com.UserData;
        import mx.collections.ArrayCollection;
        import mx.rpc.events.FaultEvent;
        
        public class UserDataRequest extends HTTPService
        {
                public function UserDataRequest(URL:String)
                {
                        super(URL);
                        this.url = URL;
                        this.resultFormat = "e4x";
                        this.addEventListener(ResultEvent.RESULT, 
resultListener);
                        this.addEventListener(FaultEvent.FAULT, faultLister);
                        this.send();
                }
                
                public function faultLister(event:FaultEvent): void
                {
                        trace(event.fault.message);
                }
                
                public function resultListener(event:ResultEvent): void
                {
                        UserData.userInfo = (event.result.user) as 
ArrayCollection;
                }
        }
}

UserData.as
------------------------------------------------------------------
package com
{
        import mx.collections.ArrayCollection;
        
        public class UserData
        {
                public static var userInfo:ArrayCollection = new 
ArrayCollection;
                
                public function UserData(){}
                
        }
}

Reply via email to