Re: [Flashcoders] Is this error prone? [loading multiple images]

2009-07-09 Thread Joel Stransky
That's good thinking. I'll have to look into it some more. This one is just
hard to test since removeEventListener fails silently if the listener isn't
on the targets listener list.

On Thu, Jul 9, 2009 at 12:53 PM, Ktu wrote:

> 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  >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
> > 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
>



-- 
--Joel Stransky
stranskydesign.com
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Is this error prone? [loading multiple images]

2009-07-09 Thread Ktu
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 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
> 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] Is this error prone? [loading multiple images]

2009-07-07 Thread Joel Stransky
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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders