I think I see a problem with this. I don't know how often GarbageCollection
runs, but if the loader you create has no references to it, and the only
event listener to it is set to have a weakReference, then the loader could
get discarded before it finishes, unless the act of loading doesn't allow it
to be removed.

Otherwise, as far as I know, that looks like it should be fine to get
reference to the loader again and remove the event listener.
?

Ktu

On Tue, Jul 7, 2009 at 12:50 PM, Joel Stransky <[email protected]>wrote:

> I'm wondering if I can use a for loop to create local Loader objects,
> assign
> listeners to their LoaderInfo objects without overwriting any of them and
> still be able to clean up after.
>
> Say I have the following inside a function body
>
> var img:Loader = new Loader();
> img.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumb, false, 0,
> true);
> img.load(new URLRequest("someImage.jpg"));
>
> and the following handler
>
> private function onThumb(e:Event):void
> {
>    var loader:Loader = Loader( LoaderInfo(e.target).loader );
>    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onThumb);
>    var thumbNail:Bitmap = new Bitmap(Bitmap(loader.content).bitmapData);
>    thumbNail.x = (itemWidth - thumbNail.width) / 2;
>    addChild(thumbNail);
> }
>
> Will the handler work its way back to the Loader that was created
> temporarily and remove a listener from it?
> Is there a better way to using throw away loaders?
>
>
> --
> --Joel Stransky
> stranskydesign.com
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to