Hi folks. I'm a novice at flex/as3. I ran into this scoping problem. I
want to find a way to store all the data I retrieve into a static class
member and access where ever and whenever I like. However, it seems as
if the static member is not in scope. Here are my codes

-----------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
  layout="absolute" creationComplete="init()">

     <mx:Style source="css/stylesheet.css"/>

     <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