QueueLoaderLite
Posted: March 11, 2008 at 11:19 amQueueLoaderLite has been deprecated. Regular QueueLoader 3.1.7 and later can be made into a lite version by removing loadable items!
I've stripped down some of the heavier features for an alternate "lite" version for those wishing a bare bones QueueLoader with low file size. QueueLoader will continue to thrive and there are some enhancements to the regular version that will be made shortly.
The lite version is focused exclusively on image and swf asset loading. Application Domain/Loader Context is still there so you can load other items within a swf and have access to its class references in the library. I will add another guide page on the Google page shortly. I'm including all the listening function in the example below just so you can see it in action, but any/all of them can be removed. More examples and documentation on this version to come, but in the meantime… Basic usage:
import com.hydrotik.utils.QueueLoaderLite; import com.hydrotik.utils.QueueLoaderLiteEvent; var qlLoader:QueueLoaderLite = new QueueLoaderLite(); var imageContainer:Sprite = new Sprite(); addChild(imageContainer); imageContainer.name = "image"; qlLoader.addItem("../flashassets/images/slideshow/1.jpg", imageContainer, {title:"image"}); qlLoader.addEventListener(QueueLoaderLiteEvent.QUEUE_START, onQueueStart, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.ITEM_START, onItemStart, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.ITEM_PROGRESS, onItemProgress, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.ITEM_COMPLETE, onItemComplete, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.ITEM_ERROR, onItemError, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); qlLoader.addEventListener(QueueLoaderLiteEvent.QUEUE_COMPLETE, onQueueComplete, false, 0, true); qlLoader.execute(); function onQueueStart(event : QueueLoaderLiteEvent):void { trace("** "+event.type); } function onItemStart(event : QueueLoaderLiteEvent):void { trace(">> "+event.type, "item title: "+event.title); } function onItemProgress(event : QueueLoaderLiteEvent):void { trace("\t>> "+event.type+": "+[" percentage: "+event.percentage]); } function onItemComplete(event : QueueLoaderLiteEvent):void { trace(">> name: "+event.title + " event:" + event.type+" - "+["target: "+event.targ, "w: "+event.width, "h: "+event.height]+"\n"); } function onItemError(event : QueueLoaderLiteEvent):void { trace(">> name: "+event.title + " event:" + event); } function onQueueProgress(event : QueueLoaderLiteEvent):void { trace("\t>> "+event.type+": "+[" queuepercentage: "+event.queuepercentage]); } function onQueueComplete(event : QueueLoaderLiteEvent):void { trace("** " + event.type); }
And for instantiating library assets in an external swf library:
import com.hydrotik.utils.QueueLoaderLite; import com.hydrotik.utils.QueueLoaderEventLite; var addedDefinitions:LoaderContext = new LoaderContext(); addedDefinitions.applicationDomain = ApplicationDomain.currentDomain; var qlLoader:QueueLoaderLite = new QueueLoaderLite(false, addedDefinitions); var soundSWF = new MovieClip(); soundSWF.name = "externalSounds"; addChild(soundSWF); var soundChannel:SoundChannel = new SoundChannel(); qlLoader.addItem(prefix("") + "flashassets/swf/externalsounds.swf", soundSWF}); qlLoader.addEventListener(QueueLoaderLiteEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); qlLoader.execute(); function onQueueComplete(event:QueueLoaderLiteEvent):void { trace("** "+event.type); var Loop1Reference:Class = getDefinitionByName("Loop1") as Class; var loop1:Sound = new Loop1Reference(); soundChannel = loop1.play(); }
QueueLoaderLite Source
The Discussion
see what everyone is saying
hi Donovan,
first of all thanks for the work you are putting here, great classes. I found your page when searching for a class that would help me out dealing with loading images. And seams i've found the place. I'm having some difficulties when using the provided code, I'm working in timeline, so just copied the code and it throws some errors:
1067: Implicit coercion of a value of type flash.display:Sprite to an unrelated type Class.
Thanks. I forgot to add the string variable for the image path. I updated the post. Where it said pt, you would add a sting path to your asset.
so i've write a comment with too much charaters :p
… just realise now. any ideias how can I write some more lines?!… cause still have some doubts I'd love to share with you
thanks
Updated the example.
Hi…
Quick question…how would I get the "queuepercentage" value from the AS2 version of QueueLoader? It has the event onQueueProgress, but I don't see the queuepercentage property.
Thanks for moving this to AS3. I use it all the time, but now need to go back to AS2 and never ran into this.
I didn't do the AS2 version, but as far as I know it doesn't support an overall monitoring percentage.
I have a little problem.
I'm loading a group of images and want to position them on the go, but if I try to get domensions of an mc:
function onItemComplete(event:QueueLoaderLiteEvent):void {
trace(img.width);
}
The function returns the dimensions only when the last onItemComplete is fired and returns 0 for every item before.
How can I position items while loading them ?
event.width and event.height will access the properties when the item has completed loading.
Thanks man, I've already done it by getting dimensions of a previous image in onItemStart but this is even easier.
I've got another problem now,
when I test the movie in Flash all event functions are fired but if I either simulate download or open the file in a browser only the first 'onItemStart' and 'onItemProgress' are fired. The first onItemComplete and the other functions (for next items) are never called although files are loaded one after another.
How to solve this ? What could I do wrongly ?
Hi, greate work, but there is one thing you have to fix:
while checking the filetype you dont check filetypes in uppercase. you should:
if(String(currItem.url).toLocaleLowerCase().match(".jpg") != null) _currType = FILE_IMAGE;
if you don't – files saved in uppercase are not loaded – and worse than that: the loading queue stops completely
hi .. first of all .. thanks for this great piece of code!
i have a question .. is there a way to pause the queue and then resume it? if yes, then i would appreciate a for some help how to do it.
thanks again
bests
alan
Not with QueueLoaderLite, but this should work with QueueLoader. download the latest from the SVN
http://code.google.com/p/queueloader-as3/
I'll try and upload the file here as well on the google code download site.. was giving me problems when I tried to update last time.
great resource. I needed this for an AS2 project and made an AS2 version available on my blog:
http://fboyle.com/blog/?p=17
not as feature rich but it may be useful none-the-less:)
-Individual monitoring
-Overall queue monitoring
-Image loading
-SWF loading
-MP3 loading
QueueLoader for AS3 was actually based on a class that was already written for AS2. Didn't have as many features, but might have saved you a little trouble:)
http://www.betriebsraum.de/blog/downloads/
…but then I wouldn't have learnt anything
Updates have been posted to the SVN.
I'm sorry… This is probably super stupid but I can't figure it out! When I try to compile the example on this page using FlashDevelop I get: "Error: Type was not found or was not a compile-time constant: QueueLoaderLiteEvent." for every listener function. I'm importing both QueueLoaderLite and QueueLoaderLiteEvent. What am I missing?
Sounds like something isn't getting imported. Can you past your code sample or better yet send it to me?
Hi Donovan
And thank you for this cool tool. I get a weird error though: every item gets loaded but events stop fireing after the first item has loaded…
Do you have some clue ?
I'd have to see the code. This is an old post, make sure you are using the latest version from googlecode svn. If you want to post a snippet I can have a look.
Hi Donovan,
Question for you. I'm using your QueueLoaderLite for a project. Works great, but I'm having a little trouble accessing the loaded SWFs, all of which have a function in them that I'd like to call before adding anything to the stage. Works with the Loader class – during the onComplete event I can use var mc:MovieClip = event.currentTarget.content as MovieClip; and then call the funtion mc.functionName(); In QueueLoaderLite i pass a MovieClip reference during the addItem call, but I can't seem to get at my functions within that MC or the QueueLoaderLiteEvent's event.targ MC.
Any suggestions would be much appreciated.
event.file.yourFunction();
QueueLoaderLite's dispose() method doesn't remove the internally registered listeners. As a result, if we attempt to call dispose() while the queue hasn't completed these handlers get triggered especially "onQueueComplete" and will throw a run-time error.
Example: Images are being loaded into a "gallery" page, user moves to another page "about us" (developer calls dispose) while images in the gallery have yet not completely loading before loading the new page.
Thanks for the catch, I've updated the SVN to QueueLoaderLite rev11.
Thank you donovan for this Lite version, it saves a lot of k's. On referencing loaded movie clips, is there a way like in QueueLoader to get "getItemByTitle" as in…"loader.getItemByTitle("mc_name)"?
event.file.yourFunction(); works fine if you need to perform some kind of action immediately onItemComplete but after everything's loaded, what if i wanted to fade up/down clips say on nav click change? i.e. what is a way to keep refences to the multiple clip instances? one way is to put them into an array i suppose. any suggestions from anyone who's figured out some work around would be appreciated! thanks.
Nope, there isn't as of yet. I'd suggest using the regular version as the size isn't too much larger. And you can always remove some of the mime types to scale it down. Should be instructions on the QL version or in this post. If you have any problems, let me know and I can explain how.
Cheers
hi donovan, thanks for your response, i will look into remove some mime types to reduce the foot print.