I linke your solution and though I usually prefer to reuse objects such as
loader, I'm not totally against creating a loader per request since in some
situations it can be handy. But let me tell you, you have a subtle bug in
your code.

You need to pin down your loader somehow, because otherwise, since it's
local to the function, it could be garbage collected. I was under the
impression that an active loader would not be collected. It's rare that this
happens, but it's possible. I've learned this the hard way, and it took a
while and some hair pulling to figure out where the problem was (I was using
a Loader object to load images, but the same principle applies to
URLLoaders).

This could be fixed by storing your loader in an instance-scoped array, and
then removing it (and its handlers) when the loader's job is done (either
because it succeded or failed), using the event.target reference to find the
loader in the array.

Cheers
Juan Pablo Califano

2010/2/26 Valentin Schmidt <v...@dasdeck.com>

> Juan Pablo Califano wrote:
> > Another option:
> > function loadXML(dfile:String,arg1:Object,arg2:Array):void
> > {
> >
> >   urlLoader.load(new URLRequest(dfile));
> >   urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void {
> >     parseXml(e,arg1,arg2);
> >   });
> > }
>
> and another option:
>
> save this as file "myURLLoader.as"
>
> package {
>  import flash.net.URLLoader;
>  public class myURLLoader extends URLLoader {
>    public var params:Object;
>  }
> }
>
> and then use something like this:
>
> function loadXML(dfile:String):void
> {
>   var urlLoader:myURLLoader = new myURLLoader();
>
>  // add arbitrary custom parameters here
>  urlLoader.params = {foo:23, bar:"hello world"};
>
>  urlLoader.load(new URLRequest(dfile));
>  urlLoader.addEventListener(Event.COMPLETE, parseXML);
> }
>
> function parseXML(e:Event):void
> {
>   trace(e.target.params.foo);
>  trace(e.target.params.bar);
>
>  xmlFile:new XML(e.target.data);
>   // ...
> }
>
> cheers,
> valentin
> _______________________________________________
> 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