Thank you guys, now I have a clearer point of view. Your responses and this thread http://www.actionscript.org/forums/showthread.php3?t=159167 helped me a lot. Have a nice day!
____________________________________________________ Claudio M. E. Bastos Iorio http://www.blumer.com.ar -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Juan Pablo Califano Sent: Tuesday, January 29, 2008 10:37 PM To: Flash Coders List Subject: Re: [Flashcoders] how to return in this function >> > var mivariable:retornaXML = new retornaXML(); >> > trace(mivariable.elXML); >> > but this trace returns null, since the xml file (I think) is not loaded >> > yet. Yes, that's the problem. In Flash, xml loading is always asynchronous so the trace line is executed immediately after the previous one, in which you created an instance of retornaXML; so the XML object isn't at that point loaded and parsed. (It would perhaps be nice to have the option of loading synchronously, but I digress...). So, you'll have to listen to the COMPLETE event dispatched by the URLLoader and then access the xml object. You can wrap your xml and the loading logic in a custom class as you seem to be doing so far, but if you're just going to load the xml and the read it / parse it somewhere else (outside that class), in my humble opinion, the wrapper is pointless. You'll end up re-dispatching the Loader events (all the events you want to support; the error events, and the complete event, at least, just in case something went wrong, and perhaps the Progress event as well) so your external code can handle the different scenarios. By the time you are done coding that, you'll find that you have a class that does almost nothing of use by itself; it just copies all the functionality that you already had in the URLLoader and XML classes out of the box. I did it a couple of times when I started to use AS 3.0, but I changed my approach as it didn't make much sense to me to have such a class. Having all that logic encapsulated in the class that actually does something with the xml, on the other hand, seems like a good idea to me. Cheers Juan Pablo Califano ----- Original Message ----- From: "Hans Wichman" <[EMAIL PROTECTED]> To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com> Sent: Tuesday, January 29, 2008 7:30 PM Subject: Re: [Flashcoders] how to return in this function > seems like an item for the newbie list tbh:) > > On Tue, Jan 29, 2008 at 8:27 PM, Claudio M. E. Bastos Iorio < > [EMAIL PROTECTED]> wrote: > >> Thanks for your answer. But how? Where?. I think that >> ProgressEvent.bytesLoaded, and ProgressEvent.bytesTotal could help. But >> where should I check the status? >> >> ____________________________________________________ >> Claudio M. E. Bastos Iorio >> http://www.blumer.com.ar >> >> -----Original Message----- >> From: [EMAIL PROTECTED] [mailto: >> [EMAIL PROTECTED] On Behalf Of eric e. dolecki >> Sent: Tuesday, January 29, 2008 4:07 PM >> To: Flash Coders List >> Subject: Re: [Flashcoders] how to return in this function >> >> you could use an event to listen to, to pass the XML out of the class. >> >> On Jan 29, 2008 1:42 PM, Claudio M. E. Bastos Iorio >> <[EMAIL PROTECTED] >> > >> wrote: >> >> > Hi guys, hope you can help me on this one. >> > >> > I have a class to load an XML file. I'm trying this: >> > >> > >> > >> > >> > package { >> > import flash.net.URLRequest; >> > import flash.net.URLLoader; >> > import flash.events.*; >> > public class retornaXML{ >> > private var _xml:XML; >> > public function retornaXML() { >> > cargarXML(); >> > } >> > >> > private function cargarXML():void { >> > var loader:URLLoader = new URLLoader(); >> > loader.addEventListener(Event.COMPLETE, xmlLoaded); >> > loader.load(new URLRequest("LocalData.xml")); >> > } >> > private function xmlLoaded(e:Event):void { >> > _xml = new XML(e.target.data); >> > trace(_xml); >> > //THE TRACE HERE WORKS PERFECT AND RETURNS THE XML >> > >> > } >> > public function get elXML():XML { >> > return _xml; >> > //THIS RETURNS null >> > } >> > >> > } >> > } >> > >> > >> > >> > I want something like this: >> > >> > >> > >> > var mivariable:retornaXML = new retornaXML(); >> > trace(mivariable.elXML); >> > >> > >> > >> > but this trace returns null, since the xml file (I think) is not loaded >> > yet. >> > What should I do? >> > >> > >> > >> > Thanks in advance. >> > >> > ____________________________________________________ >> > >> > Claudio M. E. Bastos Iorio >> > >> > <http://www.blumer.com.ar/> http://www.blumer.com.ar >> > >> > >> > >> > _______________________________________________ >> > 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 >> >> >> _______________________________________________ >> 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 _______________________________________________ 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