QueueLoader Version 3.1 – Major Update + Usage
Posted: October 29, 2008 at 9:14 pmUPDATE: 3.1.3: Fixed width and height prop in Image and SWF items. Added autoPlay to FLV. event.content returns the NetStream object and using event.content.seek(0) and event.content.togglePlay() will start the stream if the item is NOT set to autoPlay (false is the default).
UPDATE: 3.1.2: Changed path prop to URLRequest.
UPDATE: 3.1.1: Fixed an error thrown in Flex 4 SDK in FLVItem.as – Also Added version numbers to all Files. Update is on the SVN.
I'm excited to announce that QueueLoader has undergone a major revision. I finally had a chance to rewrite the class and make it more "Open Source" friendly and scalable. All loadable items have been broken out into separate classes implementing an ILoadable interface as well as extending an abstract loadable item. This will also make it easier for adding special features to loadable items, as well as promote the evolution of the package. The package path has been changed, but most of the API and general ease of use has remained the same. The most significant change is how to access loading items via the event callbacks. They have been broken out to container, targ, and content. They are explained further below in the "Useful Tips" section. I'm going to do my best to include as many frequently requested examples, but first let's go over the current features of this revision:

Source Downloads:
QueueLoader 3.1.3 Example Files + Assets + Source + Documentation :: 28.44 MB
QueueLoader 3.1.3 Source + Documentation :: 1.16 MB
Note: Both of the downloads above include the dependent libraries Popforge (.wav) and Nochump (.zip). I am not including these libraries on the SVN. Be sure to check for updates above to changes in the core QueueLoader source. If you wish to run QueueLoader without the additional libraries; In ItemList.as comment out line 45 and 46 where the zip and wav classes are being added to the loadable item list. Also comment out lines 82 and 84 in QueueLoader where the zip and wav filetype constant id numbers are defined. Finally be sure to remove ZIPItem.as and PCMSoundItem.as from the "items" package. If you wish to add your own custom item, you would simply follow the instructions in reverse but adding a unique number to the file type constant id.
Also Note: Just to clear up an possible confusion, this is a version change and not another revision. The URL to this page might be confusing as it looks like rev31 when it's 3.1.
Mailing List:
QueueLoader Google Group
General Features:
- Individual item monitoring
- Overall queue monitoring
- Bandwidth monitoring
- Standard event based handling
- Open source friendly structure
- Drawing of frames to an Array of BitmapData objects
- Automatic detection of file types
- Manual specifying of file types
- Skipping of failed loading items
- Application Domain access of loaded swf class references
- Disposal of a queue's loaded items
- Disposal of all queues added to the QLManager
- Adding items to the queue on the fly
- Access to a loaded item via getItemAt() or getItemByTitle()
- Sorting of loading queue
- Stopping and resuming of a queue
- Cache Killing
- Bitmap Smoothing
- Passing URL Variables
- Passing XML data for setting up a QueueLoader using the loadXML(); method
- Easy Access to SWF Timeline and Scope
Supported File Types:
- Image loading – jpg/gif/png
- SWF loading
- XML loading
- CSS loading
- MP3 loading
- PCM WAV loading – Using Popforge Library
- ZIP loading – Using Nochump
- FLV loading
- Generic loading – DAE/PHP/TXT/HTML
QLManager – Global QueueLoader Management:
- If I.D. is passed into QueueLoader Instance it is added to the QLManger for access
- Global disposal of all QueueLoader's added to QLManager
- Access to a Queue's targets
Useful Tips and Other Info:
- If you are loading a ton of images, you might consider putting them all on separate frames of a SWF and using the draw frames feature. If the image collection gets updated, putting them in a Zipped folder might be easier. This will alleviate the opening and closing of HTTP connections.
- event.container – access to the container you specify in the addItem() method.
- event.targ – access to the Loader of an Item in the case of an Image or SWF. This is what is added to the container DisplayObject if it has been added to the addItem() arguments.
- event.content – access to the loaded item's data or content. In the case of an Image, it would be the Bitmap. In the case of a SWF, it would be the SWF's timeline. In the case of CSS, it would be the StyleSheet. In the case of audio, it would be the Sound. Etc…
- Keep in mind QueueLoader is a utility, and not a component. Many of the more complex usage scenarios can very easily be built on top of QueueLoader. Using QueueLoader does require some basic knowledge of Actionscript 3.0, listeners, events, as well as scope. It's also much easier to extend the functionality if you are looking to modify the features of an existing loadable item. Simply replace a file type constant and add the Item to the ItemList with a regex for the filetype. Just make sure the file suffix doesn't conflict with another suffix.
- QueueLoaderLite has been included in the package and will undergo a rewrite soon as well making the distinction between the two clearer.
View the Class Documentation Files
Examples
Overall Monitoring/Basic Example
// Most Basic Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); var img:Sprite = new Sprite(); img.name = "image_1"; img.x = 20; img.y = 20; img.scaleX = img.scaleY = .075; addChild(img); _oLoader.addItem("../flashassets/images/slideshow/1.jpg", img); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Multiple Items and Event Monitoring Example
// Multiple Items and Event Monitoring Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var imageContainer:Sprite = new Sprite(); addChild(imageContainer); imageContainer.x = imageContainer.y = 25; var _oLoader:QueueLoader = new QueueLoader(); var startX:int = 0; var startY:int = 0; for (var i:int = 0; i < 3; i++) { var img:Sprite = new Sprite(); img.name = "image_"+i; img.x = startX; img.y = startY; img.scaleX = img.scaleY = .075; imageContainer.addChild(img); _oLoader.addItem("../flashassets/images/slideshow/"+(i+1).toString()+".jpg", img, {title:"Image "+i}); if (startX > 250) { startX = startX + 50; startY = startY + 100; } else { startX = startX + 150; } } _oLoader.addEventListener(QueueLoaderEvent.QUEUE_START, onQueueStart, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_START, onItemStart, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_PROGRESS, onItemProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_ERROR, onItemError,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); //Listener functions function onQueueStart(event:QueueLoaderEvent):void { trace("** "+event.type); } function onItemStart(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); } function onItemProgress(event:QueueLoaderEvent):void { trace("\t\t\t>>onItemProgress: "+event.queuepercentage); } function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); } function onItemError(event:QueueLoaderEvent):void { trace("\n>>"+event.message+"\n"); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Bitmap Smoothing and Cache Killing Example
// Bitmap Smoothing and Cache Killing Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); var img:Sprite = new Sprite(); img.name = "image_1"; img.x = 20; img.y = 20; img.scaleX = img.scaleY = 1.25; addChild(img); _oLoader.addItem("../flashassets/images/slideshow/1.jpg", img, {title:"Image 1", cacheKiller:true, smoothing:true}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Calling a SWF's Library Class References – Application Domain Example
// Calling a SWF's Library Class References - Application Domain Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var addedDefinitions:LoaderContext = new LoaderContext(); addedDefinitions.applicationDomain = ApplicationDomain.currentDomain; var _oLoader:QueueLoader = new QueueLoader(false, addedDefinitions, true, "testQueue"); _oLoader.addItem("../flashassets/swf/externalsounds.swf", this, {title:"SWF"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_START, onQueueStart, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); //Listener functions function onQueueStart(event:QueueLoaderEvent):void { trace("** "+event.type); } function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); var loop:Sound = new (getDefinitionByName("Loop1"))(); var soundChannel:SoundChannel = loop.play(0,999); }
// Queue Disposing import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); var img:Sprite = new Sprite(); img.name = "image_1"; img.x = 20; img.y = 20; img.scaleX = img.scaleY = .1; addChild(img); _oLoader.addItem("../flashassets/images/slideshow/1.jpg", img, {title:"Image 1"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); setTimeout(callDipose, 3000); } function callDipose():void{ _oLoader.dispose(); }
Manually Setting File Type/URL Variable Example
This will let you pass URL variables to a file that is to be loaded. Keep in mind that the example data.php file has no php code in it so that it will run locally. However on a php server you would have the code shown below in the data.php file. This will pass the url variable $user a value of yourname, which you should see as yourname.jpg in the XML output.
PHP:
>



'; ?>
Actionscript:
// Manually Setting File Type/URL Variable Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); var img:Sprite = new Sprite(); img.name = "image_1"; img.x = 20; img.y = 20; img.scaleX = img.scaleY = .1; addChild(img); _oLoader.addItem("../includes/admin/data.php?id=1&user=yourname", null, {title:"XML PHP", mimeType:QueueLoader.FILE_XML} ); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.title == "XML PHP") { var output:String = XML(event.targ).child("images").child("img")[0].@src; trace("\n\t\tXML Node: "+output+"\n\n"); } } function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Drawing a SWF's Frames to BitmapData Array Example
// Drawing a SWF's Frames to BitmapData Array Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/swf/externalimages.swf", null, {title:"SWF Images", drawFrames:true}); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.title == "SWF Images") { var startX:int = 0; var startY:int = 65; for (var i:int = 0; i<event.bmArray.length; i++) { var bm:Bitmap = new Bitmap(event.bmArray[i], "auto", true); bm.x = startX; bm.y = startY; bm.scaleX = bm.scaleY = .75; addChild(bm); startX = startX + 85; } } } function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Ignoring of Errors/Error Handling Example
// Ignoring of Errors/Error Handling Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(true); //<- true arg sets ignore errors var img:Sprite = new Sprite(); img.x = 20; img.y = 20; img.scaleX = img.scaleY = .075; addChild(img); var img2:Sprite = new Sprite(); img2.x = 120; img2.y = 20; img2.scaleX = img2.scaleY = .075; addChild(img2); var img3:Sprite = new Sprite(); img3.x = 220; img3.y = 20; img3.scaleX = img3.scaleY = .075; addChild(img3); _oLoader.addItem("../flashassets/images/slideshow/1.jpg", img); _oLoader.addItem("../flashassets/images/slideshow/12.jpg", img2); _oLoader.addItem("../flashassets/images/slideshow/3.jpg", img3); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_ERROR, onItemError,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemError(event:QueueLoaderEvent):void { trace("\n>>"+event.message+"\n"); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
// Stop and Resume Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(true); //<- true arg sets ignore errors var img:Sprite = new Sprite(); img.x = 20; img.y = 20; img.scaleX = img.scaleY = .075; addChild(img); var img2:Sprite = new Sprite(); img2.x = 170; img2.y = 20; img2.scaleX = img2.scaleY = .075; addChild(img2); _oLoader.addItem("../flashassets/images/slideshow/1.jpg", img, {title:"Image 1"}); _oLoader.addItem("../flashassets/images/slideshow/2.jpg", img2, {title:"Image 2"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.title == "Image 1") { _oLoader.stop(); // Set a 4 second to pause and resume the load setTimeout(resumeLoad, 4000); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); } function resumeLoad():void{ _oLoader.resume(); }
// Bandwidth Detection Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var imageContainer:Sprite = new Sprite(); addChild(imageContainer); imageContainer.x = imageContainer.y = 25; var addedDefinitions:LoaderContext = new LoaderContext(); addedDefinitions.applicationDomain = ApplicationDomain.currentDomain; var _oLoader:QueueLoader = new QueueLoader(false, addedDefinitions, true); var startX:int = 0; var startY:int = 0; for (var i:int = 0; i < 3; i++) { var img:Sprite = new Sprite(); img.name = "image_"+i; img.x = startX; img.y = startY; img.scaleX = img.scaleY = .075; imageContainer.addChild(img); _oLoader.addItem("../flashassets/images/slideshow/"+(i+1).toString()+".jpg", img, {title:"Image "+i}); if (startX > 250) { startX = startX + 50; startY = startY + 100; } else { startX = startX + 150; } } _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.bandwidth+"KB/s"); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
// CSS Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../includes/admin/test.css", null, {title:"CSS"}); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.fileType == QueueLoader.FILE_CSS) { trace("\t\tCSS: "+event.content.styleNames); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
XML Loading/Get Item By Title Example
// XML Loading/Get Item By Title Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../includes/admin/test.xml", null, {title:"XML"}); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.fileType == QueueLoader.FILE_XML) { trace("\t\tXML: "+event.content); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); trace("\n\nXML Node:\n"+XMLList(_oLoader.getItemByTitle("XML").content).queueloader.item[0]); }
// Sorting Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/mp3/GetDown.mp3", null, {title:"MP3"}); _oLoader.addItem("../flashassets/swf/externalsounds.swf", this, {title:"SWF"}); _oLoader.addItem("../includes/admin/test.xml", null, {title:"XML"}); _oLoader.addItem("../includes/admin/data.php?id=1&user=yourname", null, {title:"XML PHP", mimeType:QueueLoader.FILE_XML} ); _oLoader.addItem("../flashassets/swf/externalimages.swf", null, {title:"SWF Images", drawFrames:true}); _oLoader.addItem("../includes/admin/test.css", null, {title:"CSS"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_START, onQueueStart, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueStart(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader.getQueuedItems()); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.title == "MP3") { // This takes an array of two items (second arg) // from 4th position (1st arg) and inserts them // into the 2nd position (3rd arg) _oLoader.shuffle(4, 2, 2); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader.getLoadedItems()); }
Adding Items On-The-Fly Example
// Adding Items On-The-Fly Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/mp3/GetDown.mp3", null, {title:"MP3"}); _oLoader.addItem("../flashassets/swf/externalsounds.swf", this, {title:"SWF"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_START, onQueueStart, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueStart(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader.getQueuedItems()); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.title == "SWF") { _oLoader.addItem("../includes/admin/test.xml", null, {title:"XML"}); _oLoader.addItem("../flashassets/swf/externalimages.swf", null, {title:"SWF Images"}); _oLoader.addItem("../includes/admin/test.css", null, {title:"CSS"}); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader.getLoadedItems()); }
// QLManager Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; import com.hydrotik.queueloader.QLManager; var _oLoader:QueueLoader = new QueueLoader(false, null, true, "loader1"); _oLoader.addItem("../flashassets/mp3/GetDown.mp3", null, {title:"MP3"}); _oLoader.addItem("../flashassets/swf/externalsounds.swf", this, {title:"SWF"}); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); var _oLoader2:QueueLoader = new QueueLoader(false, null, true, "loader2"); _oLoader2.addItem("../includes/admin/test.xml", null, {title:"XML"}); _oLoader2.addItem("../flashassets/swf/externalimages.swf", null, {title:"SWF Images"}); _oLoader2.addItem("../includes/admin/test.css", null, {title:"CSS"}); _oLoader2.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueue2Complete,false, 0, true); _oLoader2.execute(); function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader.getLoadedItems()); } function onQueue2Complete(event:QueueLoaderEvent):void { trace("** "+event.type); trace(_oLoader2.getLoadedItems()); setTimeout(callDipose, 3000); } function callDipose():void{ trace("QLManager Accessing Items:"); trace("\t"+QLManager.getQueue("loader1").getItemAt(0).title); trace("\t"+QLManager.getQueue("loader2").getItemAt(0).title); QLManager.disposeAll(); trace("QLManager Disposing:"); trace("\t"+QLManager.getQueue("loader1")); trace("\t"+QLManager.getQueue("loader2")); }
Zip Loading Example
Make sure you have the nochump package in your source folder.
// Zip Loading Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/zip/assets.zip", null); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.fileType == QueueLoader.FILE_ZIP) { trace("\t\tZIP Array: "+event.content); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
PCM Wav Loading Example
Make sure the Popforge library is included in your source along with the modified SoundFactory class that bypasses the swf.bin file. This modified class writes the bytes to a ByteArray instead.
//PCM Wav Loading Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var soundChannel:SoundChannel = new SoundChannel(); var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/pcm/loop1.wav", null, {title:"Loop1"}); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.fileType == QueueLoader.FILE_WAV) { soundChannel = event.content.play(0,999); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
MP3 Loading Example

Audio taken from Islands of Chill. This album is great!
//MP3 Loading Example import com.hydrotik.queueloader.QueueLoader; import com.hydrotik.queueloader.QueueLoaderEvent; var soundChannel:SoundChannel = new SoundChannel(); var _oLoader:QueueLoader = new QueueLoader(); _oLoader.addItem("../flashassets/mp3/GetDown.mp3", null, {title:"MP3"}); _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true); _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true); _oLoader.execute(); function onQueueProgress(event:QueueLoaderEvent):void { trace("\t>>onQueueProgress: "+event.queuepercentage); } function onItemComplete(event:QueueLoaderEvent):void { trace("\t>> "+event.type, "item title: "+event.title); if (event.fileType == QueueLoader.FILE_MP3) { soundChannel = event.content.play(0); } } function onQueueComplete(event:QueueLoaderEvent):void { trace("** "+event.type); }
Direct QL Formatted XML Loading Example
This snippet of XML can reside anywhere in your XML document. It allows for automatic passing of QueueLoader data. The prefix attribute simply adds the prefix when the movie is in external/standalone mode when publishing locally. If your paths jump directories or require absolute paths, then you can leave it as prefix="".
XML:
The loadXML() method also accepts a scope variable which relates to the container attribute. I.E. scope[container]. If it's null, then the container has no parent reference and is the same as adding null to an addItem() method. Actionscript:
//Direct QL Formatted XML Loading Example
import com.hydrotik.queueloader.QueueLoader;
import com.hydrotik.queueloader.QueueLoaderEvent;
var _oLoader:QueueLoader = new QueueLoader();
_oLoader.addItem("../includes/admin/test.xml", null, {title:"XML"});
_oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true);
_oLoader.execute();
function onQueueProgress(event:QueueLoaderEvent):void {
trace("\t>>onQueueProgress: "+event.queuepercentage);
}
function onItemComplete(event:QueueLoaderEvent):void {
trace("\t>> "+event.type, "item title: "+event.title);
if (event.title == "XML") {
_oLoader.loadXML(event.content);
}
}
function onQueueComplete(event:QueueLoaderEvent):void {
trace("** "+event.type);
}
//SWF Timeline Example
import com.hydrotik.queueloader.QueueLoader;
import com.hydrotik.queueloader.QueueLoaderEvent;
var _oLoader:QueueLoader = new QueueLoader();
_oLoader.addItem("../flashassets/swf/timeline.swf", this);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true);
_oLoader.execute();
function onQueueProgress(event:QueueLoaderEvent):void {
queueprog.width = 150 * event.queuepercentage;
queue_txt.text = "QUEUE: "+Math.round((event.queuepercentage*100)).toString() + "% COMPLETE";
}
function onItemComplete(event:QueueLoaderEvent):void {
trace("\t>> "+event.type, "item title: "+event.title);
if (event.fileType == QueueLoader.FILE_SWF) {
event.content.fireFunction();
event.content.gotoAndPlay(2);
}
}
function onQueueComplete(event:QueueLoaderEvent):void {
trace("** "+event.type);
}
//Generic Data Loading Example
import com.hydrotik.queueloader.QueueLoader;
import com.hydrotik.queueloader.QueueLoaderEvent;
var _oLoader:QueueLoader = new QueueLoader();
_oLoader.addItem("../queueloader.html", null, {title:"HTML"});
_oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true);
_oLoader.execute();
function onQueueProgress(event:QueueLoaderEvent):void {
trace("\t>>onQueueProgress: "+event.queuepercentage);
}
function onItemComplete(event:QueueLoaderEvent):void {
trace("\t>> "+event.type, "item title: "+event.title);
if (event.title == "HTML") {
trace(event.content);
}
}
function onQueueComplete(event:QueueLoaderEvent):void {
trace("** "+event.type);
}
Source Downloads:
QueueLoader 3.1.2 Example Files + Assets + Source + Documentation :: 28.44 MB
QueueLoader 3.1.2 Source + Documentation :: 1.16 MB
The Discussion
see what everyone is saying
Nice work man! Did a brief review and I'm definitely excited to get my hands dirty. Definitely a fan of the zip support.
[...] QueueLoader gibts nun in einer neuen Version. Mehr Infos findet man dazu [...]
Awesome let me know how it goes, and if there's anything you want to add:)
Super nice.
2 examples that got my attention were "Drawing a SWF’s Frames to BitmapData Array" and "Queue Disposing".
Is this latest revision making use of Flash 10?
In my project I use FileReference a lot. Perhaps there's a case to integrate the FileReference.load() into QueueLoader.
Thanks Bjorn! Currently it is not, however I plan on doing a version for 10 soon. And FileReference.load() is on my list of items to add.
hi Donovan,
Great work you have here!
One doubt, I was checking the demo and one thing that realise is that memory keeps rising as you make the queue start over. Don't know if this is normal, but once you dispose it should free memory no?
Thanks for the great updates to the utility. Question about the shuffle method, what is the best way for shuffling items to the top of the queue that have yet to load. For instance, a button is clicked for an asset to display, but that asset has not loaded yet. Can shuffle kill the current load and promote the needed asset to the top of the queue and execute it?
sorry, my mistake, after several presses in start, memory rises, click dispose and memory stays the same… but if click again in start the memory starts from normal (low) value.
so disposal works great
sorry the panic
really great work the way you can acesses loaded objects (event.container/event.targ/event.content)
Just make sure you test his in the browser. unload() and therefore dispose() doesn't properly show the memory amount when you are testing within the Flash IDE.
Thanks so much!
Yes, but you can't insert items in front of anything that is in the process of loading. If the stop() call comes within an itemComplete handler or before the itemComplete event is fired, then it will make the adjustment before the next item starts loading. Keep in mind shuffle() will not stop the current load, you would need to call stop() first then perform your shuffle duties.
Hope that helps!
Thank you. To clarify, after stopping the queue prior to shuffling, would I need to shuffle the new items to the top of the queue or to the location where the queue is stopped before resuming? Again, many thanks.
The index is the index for the entire list of items. So if an item has loaded, the length of the list as well as the index position doesn't change. So if you've loaded one item and you want to shuffle 2 items to the next index you would insert them in position 1 (0 being the index for the first item) with a len of 2. And of course you would need to specify the index of where the 2 items are coming from. So you need an index for the source position, the length of the items, and an index of the destination position. That being said, to answer your question, You would need to insert them into the position of where the load has stopped. You couldn't insert them into index 0 as that has already completed. event.index will access the Queue's current index. So you could do something like queue.shuffle(sourceIndex, 2, event.index);
I try the queueloader.fla and i have an error :
///////////////////////////////////////////////
TypeError: Error #1010: Un terme n'est pas défini et n'a pas de propriété.
at queueloader_fla::MainTimeline/onItemComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.hydrotik.queueloader::QueueLoader/dispatchEvent()
at com.hydrotik.queueloader::QueueLoader/completeHandler()
at com.hydrotik.queueloader.items::XMLItem/preCompleteProcess()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
** queueComplete
///////////////////////////////////////////////////////////
Can somebody help me ?
Thanks
Replace the onItemComplete handler with this code:
function onItemComplete(event:QueueLoaderEvent):void {
//trace("\t>> "+event.type, "item title: "+event.title);
end_output.text = end_output.text + (event.index+1) + ": " + event.title + "\n";
if (event.title == "MP3") {
_oLoader.shuffle(6, 3, 1);
}
if (event.title == "XML PHP") {
var dat:String = XML(event.content).child("images").child("img")[0].@src;
php_data.text = dat;
}
if (event.fileType == QueueLoader.FILE_CSS) {
trace("CSS: "+event.content.styleNames);
}
if (event.fileType == QueueLoader.FILE_MP3) {
soundChannel = event.content.play(0,999);
}
if (event.title == "ZIP") {
trace(event.content);
}
if (event.title == "SWF Images") {
startX = 0;
startY = 65;
for (var i:int = 0; i
var bm:Bitmap = new Bitmap(event.bmArray[i], "auto", true);
bm.x = startX;
bm.y = startY;
bm.scaleX = bm.scaleY = .75;
imageContainer.addChild(bm);
startX = startX + 85;
}
}
}
I will update the download file. You can also refer to the example.fla as this is the same file that the examples in the post are using.
oK I WILL TEST IT.
Can you tell how integrate it in a main class ? not using the timeline ?
I have an other question :
I will used it to download files witch contain font.
How can i access it ? (sorry for my bad english and bad actionscript …)
There is a sample Class file in the root src directory
add the font to an external swf, and call is using the application domain. Then access the font using its class reference.
Thanks a lot !!!
i'm sorry but i have a another question :
I try the class :
///////////////////////////////////////////////
package {
import de.popforge.audio.processor.fl909.voices.Voice;
import flash.display.Shape;
import flash.system.Capabilities;
import flash.text.TextField;
import queueloader.QueueLoaderEvent;
import queueloader.QueueLoader;
import flash.events.EventDispatcher;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.display.Sprite;
public class AssetLoader extends EventDispatcher {
private var addedDefinitions : LoaderContext
private var _oLoader : QueueLoader
public function AssetLoader ():void {
addedDefinitions = new LoaderContext(false, ApplicationDomain.currentDomain);
_oLoader = new QueueLoader(false, addedDefinitions, true, "testQueue");
_oLoader.addItem(prefix("") + "includes/admin/test.xml", null, {title:"XML", cacheKiller:true});
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_START, onQueueStart, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_START, onItemStart, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_PROGRESS, onItemProgress, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_ERROR, onItemError, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_PROGRESS, onQueueProgress, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete, false, 0, true);
_oLoader.addEventListener(QueueLoaderEvent.ITEM_HTTP_STATUS, onHTTPError, false, 0, true);
_oLoader.execute();
}
private function onQueueStart(event : QueueLoaderEvent) : void {
trace("** " + event.type);
}
private function onItemStart(event : QueueLoaderEvent) : void {
trace("\t>> " + event.type, "item title: " + event.title);
}
private function onItemProgress(event : QueueLoaderEvent) : void {
trace("LOADING " + event.title.toUpperCase() + ": " + Math.round((event.percentage * 100)).toString() + "% COMPLETE");
}
private function onQueueProgress(event : QueueLoaderEvent) : void {
trace("QUEUE: " + Math.round((event.queuepercentage * 100)).toString() + "% COMPLETE");
}
private function onItemComplete(event : QueueLoaderEvent) : void {
trace("\t>> " + event.type, "item title: " + event.title);
}
private function onItemError(event : QueueLoaderEvent) : void {
trace("\n>>" + event.message + "\n");
}
private function onHTTPError(event : QueueLoaderEvent) : void {
trace("\n\t\t>>"+event.message+"\n");
}
private function onQueueComplete(event : QueueLoaderEvent) : void {
trace("** " + event.type);
}
private function prefix(serverPath : String) : String {
var playerType : String = Capabilities.playerType;
if (playerType == "External" || playerType == "StandAlone") {
return "../";
} else {
return serverPath;
}
}
}
}
/////////////////////////////////
and il will great.
Is it possible to create a class array with replace this lign
_oLoader.addItem(prefix("") + "includes/admin/test.xml", null, {title:"XML", cacheKiller:true});
My idea is to generate multiple addItem using a array and a external file (xml for exmample)
Yes, check the multiple loading example. Or you can try the loadXML() method and add you items to an XML file.
Hi, Donovan
It's my first time to comment on this blog and I think I've found a bug on QueueLoader.
At QueueLoaderEvent, the data type of "path" is defined as String but I reckon it should be URLRequest as it passes the data fom AbstractItem's "path" which is defined as URLRequest.
Otherwise it should be converted to String type during the event's constructor.
I've amend it for myself but could you fix this at the next minour update?
BTW, I truely appreciate both of QueueLoader and HydroTween.
They are really helpful.
I'm wondering if I can change the height and width of the sprite where the imgs are being added? Example would be:
imageContainer.height = swfStage.stageHeight
When I try it nothing is displayed where if I delete the line the images load and appear in the movie.
Help please.
Yes you can. Did you try using an absolute number? stage properties don't work as they should depending on the browser. Also try defining the container dimensions after the image has loaded.
SVN and Google have been updated with 3.1.2. Thanks for the catch!
When using a Video or VideoPlayer object as the container for FLV items, I am getting 'null' when I trace(event.content) in the onItemComplete event call back. Is there another way to trace the target that the FLV has loaded into?
Thank you
Use event.container
Hi,
I copied and paste your code as is from the swf timeline example and I m geting alot syntax errors.
Would you know whats going on..
If you copied the code from the example into another file, there are sections of code you need to copy from the first frame.
If you are experiencing errors in the example, it's probably because you have another example in another frame that is uncommented out.
Feel free to send me your code as well.
nevermind i got it.
folks becareful when copying the code u made have to rewrite the " character.. becuse it comes in as curly quotes which are incorrect..
Yeah that's an annoying thing about blogs. I'l have to see if I can switch the smart quotes char for the regular one in the wordpress plugin code.
Found a plugin to untexturize the blog. Shouldn't be an issue anymore:)
Updates have been posted.
thats ace! you just saved me a whole lot of time… keep on truckin…
i appreciate all the effort that's gone into this! i just had a quick question…
is there a reason "index" has been left out of the QueueLoaderLiteEvent? Is there an equivalent variable in the lite version?
not really. Redoing QueueLoaderLite is on my list of things to do, but at this point I would suggest using the newer version of QueueLoader. QueueLoaderLite will be QueueLoader with some of its loadable items removed, which can be easily done with ItemList and removing the items you don't want. Beyond that I haven't drawn up plans for the lite version update.
Hi Donovan
thanks for the great work, I have used an earlier version of Queueloader for a previous project, and I am now looking forward to using this new version for my next project.
I would like to utilize the ZIP feature, and have done some testing with it. I can load the ZIP (a file with lots of jpgs in it), but how do I extract the images to be used in flash?
There should be a zip example in one the exmples fla. Also check out the nochump site as well for more advanced stuff.
Greetings Donovan.
Just wanted to say thanks for your work; was linked to it and compared it against BulkLoader and decided to use this – worked for me in just a few moments as I needed it to work.
Thanks William! Great to hear!
Hey, just started using your loader class, fantastic work
Just wanted to share 2 things with you (and any othes that might be interested) :
1. In the main Queuloader class, you have a call to getMode() which returns false if you are using the Flash IDE. Not sure of the reasons for this, but to overcome issues with loading live data in tet mode, I added a test in the addItemAt function (line 209) :
var urlReq:URLRequest = (info.ignoreMode) ? new URLRequest(src) : new URLRequest(strip[0] + ((getMode() && urlVars.length > 1) ? urlVars : ""));and I pass ignoreMode = true in the addItem info object.
The second thing I found useful was to allow queueloader to handle loading of crossdomain policy files. I hacked up my version to handle this, but it might be something you'd consider ading to a future revision.
Top stuff
/dan
Hi m8,
i have a problem here when calling loadMC function(root) from nested mc(menu) all mc´s getting loaded to same target, first load works but then
>> itemStart item title: null
>> item target: [object Loader]
>> itemProgress: percentage: 0
>>onQueueBytesLoaded: 0
>>onQueueBytesTotal: 51725
[object SWFItem]
>> itemProgress: percentage: 1
>>onQueueBytesLoaded: 51725
>>onQueueBytesTotal: 51725
[object SWFItem]
TypeError: Error #1006: value ist keine Funktion.
at com.hydrotik.queueloader.items::SWFItem/preCompleteProcess()
thx !
Hallo, i've loaded my swf to some target MC eq. targetMC
LoaderSubPages.addItem("test.swf", targetMC, {title:"test"});
In test.swf i've function some()
How can i execute this function by CLICK on some others button?
Thanks P
event.content.function();
would access the timeline in an itemComplete handler.
Yes yes, but how can i access to function in loaded content by clicking on some button, not by onComplete handler?
Of course movieClip is loaded
I've tried to use a targetMc.content.testFunction("X")
But it doesnt work. Undefined property
testFunction is alredy in loaded movieClip
Thanks again
P
Hi,
i have a very strange problem with bigger files.
I have six swf files in my loading queue. Each file is round about 7-8 MB. The loading queue class holds sometimes in the middle of item 1 to item 3 and doesn´t load anymore. Don´t know what to do know. Because when i get out the embedded video files everything runs fine.
Maybe you can give me a hint what it can be?
Thanks
Peter
What version are you using? If it's anything after 3.1.3, I can't imagine what it would be unless it's an issue with the loader Class dealing with files over a certain size. If you have a place where I can take a look, or send the source, then I could make a better assessment of what it could be.
i use version 3.1.7, i finished know the loading logic and i think everythings runs fine now, but my problem is that my output window doesn´t show me all events. Sometimes it stopping to show me the progress, so that i thought i had a loading problem, but loading went fine. And when i shuffle the priority of my loaded movies the output window doesn´t show me all item start events. Maybe there is something wrong with cs4, i don´t know. Did you had some similar problems with bigger files? It´s the same with all fired events of QueueLoaderEvent. When you are interested, i can show you the files offlist.
Thank you for this… I think the only thing missing is clear documentation. To be fair, for those who are not so advanced
But for real, thanks…!
There are a lot of examples on the blog that cover most of the basic usage of the library. Also the download has a number of examples. Was there something in particular you are looking for? First time I've heard of missing clear documentation, so if you have suggestions, I'd love to hear them.
[...] that I provide detailed guides for people and a website to promote QL. There are plenty of examples within this blog as well as a place on github to keep track of QueueLoader and (hopefully) promote [...]