Am I Crazy? Question About Using AS3 Loader

EDIT 3/20/09: Thanks to Andre Anaya in the comments I figured out what my issue was. Apparently I have to run the loader.unload() method in my Event.INIT before going on and loading the next asset. Thanks Andre!

I normally don’t like to do this on here but I’m at a loss right now. I just spent about three hours troubleshooting some code because it wasn’t working in Flash Player 9 (but working fine in 10). The situation is this: I was loading some images sequentially and I had a loader instance defined at the top of my class and then added listeners etc. in my constructor. I then was reusing that loader instance to load future images. This was working fine in FP10 but the client came back and said it wasn’t showing the images after the first load in FP9 (any version of FP9, actually, as I tested it). I had to go through and each time I wanted to load a new image I had to re-create the loader and its listeners and then it worked flawlessly in FP9. What on earth am I missing here about FP9 that seems to work in FP10? I tried doing some Googling about it but nothing really noteworthy came up. Can anyone please explain to me why this was happening in FP9? Thanks in advance for whoever can do that for me.

If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.


Hi Matt, you sure you’re not using weak listeners for events or use loader instance declared on the fly? I’ve had troubles with it once, when my event listeners suddenly stopped listening. Garbage collector was kicking in differently in FP9 and FP10.

That’s very strange, I wonder if (in FP 9 atleast) if the Event.COMPLETE Event is only fired once per Loader instance?

I spent a few months building a global site preloader that uses idle-time to sequentially load site assets by priority. I developed it for, if you go to the site in Safari you can see the loading system in action, just hit the homepage and watch what the activity panel does. I’ll be releasing it soon, and I’ve tested it rigorously in FP 9 and FP 10, so hopefully it can save you some future headaches…

The docs for the loading system are here, but again I haven’t released it yet.

Is there any chance this could be some sort of security issue? I’ve noticed difference with security from fp9 to fp10, but usually its stuff that works in fp9 but not fp10.

@Tomek: I am using weak references to the listeners, maybe that is the issue in FP9, although i’ve never seen the GC kick in so fast. my understanding was that GC kicked in at a certain point when your memory was filling up too much?

@JP DeVries: Your class looks nice but it looks like alot more than I want to do, but maybe i just need to focus in on what i want to do in it and not all the other possibilities. i like the simple usage of my SequentialLoader.

and i did initially think it was a security issue but all images are being loaded from the same domain so i crossed that out. it was literally an issue with the Loader.

Yea the Loading System I did is really only designed for large sites where preloading is desired, and I’d only use it when starting a project. Things I do like about it is once its set up your loading is pretty much taken care of, and turning on global preloading is pretty much a flip of a switch.

have a look at this:

seems it’s a know bug of fp9

Thanks @sitron, good lookin’ out

@sitron: good find, altho my error wasn’t the same as that one, but it seems theres more than one issue with it in FP9. Blast old technology!

It’s realy hard to kwon what’s going on without any code or erros, but i did a small sample of a load queue.
Hope this help you to figure out what’s going on.

I’ve created a loader class that I use in my works, that works just fine for me. There a no documentation yet but there’s an example of usage. Yout can check it out at my googlecode.

It’s called DataLib. You can add itens to a queue and load them. After that, all itens that you’ve loaded are stored to safe future load request for the same item. You can also delete any item from the lib to free memory. It support jpg, gif, png, swf, xml, and binary files.

It’s a static class so you don’t need to instantiate it and you can acess any loaded data from any part of your application.

@Andre: You’re the man. I figured out what the problem is in FP9 by looking at your files. I had to do an unload() on the content in my Event.INIT method before loading the next one! SWEET!

When you finish your work, please send me the link.

@Andre: Unfortunately I can’t show it to you because it is password protected 😛

[…] passada estava olhando o Flash Bookmarks e vi que uma dúvida foi postada em relação ao Loader. Um tempo atrás eu precisei carregar um arquivo utilizando um […]

Yeah, the loader Class in FP9 is pretty buggy when using it as the basis for repeated loads into a single Loader instance. Especially so if you then reparent the loaders content. Seems that the Loader class does not check for the existence of its content when you ask it to create subsequent loads. Internally I think the class tries to unload any existing content, finds its not there and spits the dummy. When it clearly should check, see there is no content to unload and carry on as normal. Its an obscure bug, but one thats caught me out. As your found, its fixed in FP10, thankfully.

Leave a comment