Have your XMLLoader class extend EventDispatcher and have your XMLLoader
class dispatch an event when the load is complete.  Wherever your
instance of the class is declared, add an event listener to the instance
and write a function handler. if you need assistance with setting that
up, write back, it's pretty simple.


Jason Merrill
Bank of America  
GT&O and Risk L&LD Solutions Design & Development 
eTools & Multimedia 

Bank of America Flash Platform Developer Community


Are you a Bank of America associate interested in innovative learning
ideas and technologies? 
Check out our internal  GT&O Innovative Learning Blog & subscribe.




 

>>-----Original Message-----
>>From: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf 
>>Of Allandt Bik-Elliott (Receptacle)
>>Sent: Thursday, March 27, 2008 2:51 PM
>>To: flashcoders
>>Subject: [Flashcoders] using a class to load data
>>
>>hi guys
>>
>>i am trying to set up a class to handle my xml (will be 
>>instantiated for each xml file) but i'm running into a slight problem
>>
>>here is the class so far:
>>
>>CODE
>>package
>>{
>>      //package imports
>>      import flash.events.*;
>>      import flash.net.*;
>>      
>>      internal class XMLLoader
>>      {
>>              // class variable declarations
>>              private var xmlDoc:XML;
>>              private var xmlURL:String;
>>              private var xmlLoader:URLLoader;
>>              
>>              public function get doc():XML {return xmlDoc;}
>>              
>>              // constructor
>>              public function XMLLoader(url:String)
>>              {
>>                      xmlURL = url;
>>                      var urlRequest:URLRequest = new 
>>URLRequest(xmlURL);
>>                      xmlLoader = new URLLoader();
>>                      
>>xmlLoader.addEventListener(Event.COMPLETE, completeListener);
>>                      xmlLoader.load(urlRequest);
>>              }
>>              
>>              private function completeListener(e:Event):void
>>              {
>>                      xmlDoc = new XML(xmlLoader.data);
>>              }
>>      }
>>}
>>/CODE
>>
>>the problem is with timing - from within the XMLLoader() 
>>Class i can wait for the COMPLETE event to reference the 
>>xmlDoc but how would i do that from an instance of the class?
>>
>>for instance if i do the following from my main class i get a 
>>null object error because it doesn't wait for the data to be 
>>loaded before trying to read it:
>>
>>CODE
>>var xmlurl:String = "path/to/xml.xml";
>>var xmlDoc:XMLLoader = new XMLLoader(xmlurl); xmlDoc = 
>>xmlLoader.doc; trace (xmlDoc.toXMLString()); /CODE
>>
>>this would equally apply to an image loader, i guess
>>
>>thanks in advance
>>a
>>
>>Allandt Bik-Elliott
>>thefieldcomic.com
>>e [EMAIL PROTECTED]
>>
>>_______________________________________________
>>Flashcoders mailing list
>>Flashcoders@chattyfig.figleaf.com
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to