Search code examples
actionscript-3loader

Event.COMPLETE or Event.INIT for a sequential loader


So, I'm making my own sequential loader. It has different functions for SWF, FLV and image files. Now, to make it sequential (loading goes on one by one) I'll use loader.contentLoaderInfo events and there are these two events called COMPLETE and INIT. After some reading, I understood that both events have some weaknesses in the terms of "completeness" of the loading. INIT seems a better option for images, while COMPLETE is for SWFs (I'm not sure which one is better for FLVs). The difference is little, but I'm worried about future problems regarding to it. Can you give me a suggestion on this?


Solution

  • I used the complete event as a sign that the image was loaded for a batch image loader I put together as a demo project to attempt to preload data for a game, the code can be seen here (sorry for the poor project naming, they always start off as something else :)

    http://www.shaunhusain.com/DrawTextRandomly/srcview/

    demo here: http://www.shaunhusain.com/DrawTextRandomly/

    in src/util/imageLoading/BatchImageLoader.as

    I basically setup this class so I would give it the folder to load images from and a collection to populate, then tell it what the start and end numbers are for the set of images, the images are generated by Blender with it's default file naming scheme using 0 padded counts for each frame, so I was able to make those animations exported from blender easy to load up into a collection that I can later use to do flipbook style animations.

    Let me know if this is helpful or you were looking for something more specific I might be able to answer. I've generally used complete to know when data is loaded regardless of type and haven't experienced any issues (loaded images, mp3s, flvs, xml and I pretty heavily rely on COMPLETE to know when the data is ready to manipulate without issue so far, always possible there's edge cases I haven't encountered though).

    From reading a bit in the article as well it seems init may be fired earlier than complete before the full data is available, unless you're concerned with manipulating the objects as early as possible, I think COMPLETE is probably a safer way to go. I believe the concern to wait for INIT is only if you're attempting to use the SWFLoader or the like itself not the data directly from the Loader (though this is just a guess based on the article).