Add

AS3 + XMLLoader + CSSLoader


Someone suggested the great idea of adding CSS and XML loading to QueueLoader. I plan on doing this, but first I thought I'd share a method I use to load those two items.

I personally tend to load XML first (I put the path to the css in the XML file), then I load the CSS, and then I start my QueueLoader. The reason for this is that I almost always store the paths for QueueLoader in the XML. If that's a method you tend to follow as well, then these utilities will help if you haven't built them already.

In the spirit of sequential loading and monitoring, I totally plan on adding this to the next revision. However, I would not suggest setting up a separate QueueLoader just for XML and CSS. If you need to load them separately, here are a couple of utilities for doing that. They will save you a bit of overhead, and are cousins of QueueLoader so they should be brainless to implement.

XMLLoader

import com.hydrotik.utils.XMLLoader;
import com.hydrotik.utils.XMLLoaderEvent;
 
 
var xmlLoader:XMLLoader = new XMLLoader(_sAdminPath + xmlFilename);
xmlLoader.addEventListener(XMLLoaderEvent.COMPLETE, onXMLComplete);
xmlLoader.addEventListener(XMLLoaderEvent.ERROR, onXMLError);
xmlLoader.addEventListener(XMLLoaderEvent.PROGRESS, onXMLProgress);
 
 
function onXMLError(event:XMLLoaderEvent):void {
    trace("XMLLoader error: "+event);
}
 
function onXMLProgress(event:XMLLoaderEvent):void {
    trace("XMLLoader progress: "+event.percentage);
}
 
function onXMLComplete(event:XMLLoaderEvent):void {
    xml = event.xml;
}

CSSLoader

import com.hydrotik.utils.CSSLoader;
import com.hydrotik.utils.CSSLoaderEvent;
 
 
var cssLoader:CSSLoader = new CSSLoader(_sAdminPath + xmlFilename);
cssLoader.addEventListener(CSSLoaderEvent.COMPLETE, onXMLComplete);
cssLoader.addEventListener(CSSLoaderEvent.ERROR, onXMLError);
cssLoader.addEventListener(CSSLoaderEvent.PROGRESS, onXMLProgress);
 
 
 
function onXMLError(event:CSSLoaderEvent):void {
    trace("CSSLoader error: "+event);
}
 
function onXMLProgress(event:CSSLoaderEvent):void {
    trace("CSSLoader progress: "+event.percentage);
}
 
function onXMLComplete(event:CSSLoaderEvent):void {
    css = event.css;
}

I didn't include any fla files in the download, just the packages, since this should be pretty easy to implement. But here's an example of how I use these before running my main block of code:

private function loadConfigration():void{
    var xmlLoader:XMLLoader = new XMLLoader(_sAdminPath + xmlFilename);
    xmlLoader.addEventListener(XMLLoaderEvent.COMPLETE, onXMLComplete);
    xmlLoader.addEventListener(XMLLoaderEvent.ERROR, onXMLError);
    xmlLoader.addEventListener(XMLLoaderEvent.PROGRESS, onXMLProgress);
}
 
private function onXMLError(event:XMLLoaderEvent):void {
    trace("XMLLoader error: "+event)
}
 
private function onXMLProgress(event:XMLLoaderEvent):void {
    trace("XMLLoader progress: "+event.percentage)
}
 
private function onXMLComplete(event:XMLLoaderEvent):void {
    trace(":: onXMLComplete:");
    _xml = event.xml;
 
    var cssLoader:CSSLoader = new CSSLoader(CacheKiller.file("includes/admin/" + _xml.attribute("css"), "../", "/"));
    cssLoader.addEventListener(CSSLoaderEvent.COMPLETE, onCSSComplete);
    cssLoader.addEventListener(CSSLoaderEvent.ERROR, onCSSError);
    cssLoader.addEventListener(CSSLoaderEvent.PROGRESS, onCSSProgress);
}
 
private function onCSSError(event:CSSLoaderEvent):void {
    trace("CSSLoader error: "+event)
}
 
private function onCSSProgress(event:CSSLoaderEvent):void {
    trace("CSSLoader progress: "+event.percentage)
}
 
private function onCSSComplete(event:CSSLoaderEvent):void {
    trace(":: onCSSLoaded:");
    _css = event.css;
    buildInterface();
}

Pretty simple:) Just runs one after the other then you can run a QueueLoader with loaded items pulled from the XML. Just one way of doing, but like I said I will add css and xml to the next revision.

Thanks to Jesse for the idea!


XMLLoader and CSSLoader Source Rev1

The Discussion

see what everyone is saying

  • tasovi November 7th, 2007 at 12:25 pm #1

    Hi,
    I tried the XMLLoader class, but I don't get a loadingprogress state.

    the progress event is just triggered once and the loaded percentage is 1.

    do you know why?
    thx!

  • djdonovan November 7th, 2007 at 12:41 pm #2

    I'm getting progress output when I publish my files. Are you simulating download when you test your movie? Could also be that your XML is small?

  • tasovi November 8th, 2007 at 10:58 am #3

    I am simulation via the Flash IDE. The xml has 40kB.
    when i am loading a bigger file (700kb) progress is trigger a just before complete is triggered. then I get about 5 progress events triggered all at once! strange!

    are you planing to integrate the xml and css loader into Queloader? That would be great!!!!!!!!!

  • djdonovan November 8th, 2007 at 12:19 pm #4

    I'll get your xml offline and check. Yes I am almost finished adding those to the QueueLoader as well as adding items on the fly while a load is runnning

  • tasovi November 8th, 2007 at 12:53 pm #5

    can't wait to test the new version of the loader!!!!!!!!!!!!

  • Chris Elmes February 14th, 2008 at 5:07 pm #6

    Nice Class…

    I get a progress out put of 1 also, after using a larger file I got a 0.69 and a 1 so I looked at your code and it looks liek it just needs a *100 after you calculate the bytes loaded/toal bytes, basically 1 is 100% (kinda like alpha is now in as3)

  • djdonovan February 15th, 2008 at 12:15 am #7

    Yes Chris you are correct. The loader is using the as3 convention of percentages instead of 0-100 n as2. Also makes it easier for calculating load bar widths, etc.

  • Silentium March 22nd, 2008 at 6:58 am #8

    Great Work. I'm using this Libs with FB3 since a few days. I Noticed that the Constructor of the LiteEventClass uses the constant filetype.
    At the Moment this causes compile a error realted to this compiler bug: http://bugs.adobe.com/jira/browse/ASC-2231.

    coriously i changed filetype : int = QueueLoaderLite.FILE_IMAGE to filetype : int = 1 than i could compile.

  • djdonovan March 22nd, 2008 at 1:15 pm #9

    This post is in the wrong place, but thanks. I'll update that in the next update in the next couple days.

Respond

get in on the action.

* Required

bottega veneta deep coffee pocket bag deep weight loss pills bingo and game casino gambling online virtual how to win at slots versace deep coffee venus bag women does viagra work online bingo uk discount drugstore where to get viagra or cialis diazepam cheap without rx bingo and slots does cialis really work bingo gaming chanel yellow shoulder bag bingo for cash slot machine buy meds online without presciption lancel pearl premier flirt prada white shoulder bag prescriptions pain killers without a prescription viagra product information cialis generic levitra viagra cialis male enhancement online gambling offers manolo blahnik beige hangisi valium indications anya hindmarch beige hobo how does diazepam work who has the cheapest cialis price for tramadol levitra website price for generic viagra top anti depressants pharmacy zolpidem marc jacobs antique gold keylock messenger bag pill for acne casino gambling buy carisoprodol cheap create poker website zyban tablet jimmy choo purple wells shoes valtrex medication counseling for erectile dysfunction hey bingo louis vuitton patent beige sandals louis vuitton monogram idylle pink tote power bingo slot games gucci black evening bag xanax fedex oral jelly viagra new casino slots discount erectile dysfunction medication christian louboutin white ambrosina pumps poker machine games buy no phentermine prescription high stakes poker buy tory burch golden reva ballerina flats casino locations roulette casinos play online casinos bingo and slots viagra effect on women louis vuitton damier graphite keepall bandouliere marc jacobs royal blue keylock shoulder bag play roulette online casino mania online buy compazine buy gucci black trainers online casinos en internet how to win slots christian louboutin blush barcelona sandals prescription diet drugs us only mobile casino games natural clomid buy overseas viagra online casino canada online xanax fedex norvasc generic erectile dysfunction products zoloft canada uk viagra supplier casino bonus tory burch deep blue tory logo rain boots poker for money prescription drugs online adipex no prescription needed pharmacies geniune cialis no prescription ambien dosing how do muscle relaxants work valentino beige snakeskin clutch what is tadalafil ativan dosages sales viagra ysl white muse bag cialis to buy online gambling strategy cheapest phentermine pills christian dior biege medium saddle handbag alprazolam brand cheap viagra new zealand low cost adipex bally patent patent red jana tote ambien pharmacy manolo blahnik bow booties what is viagra used for dosage viagra new diet pill fda approved play slots online now cialis best price las vegas bingo cialis generic tabs versace purple venita bow satchel chloe patent purple cyndi tote fendi apricot snake peekaboo handbag discount lipitor prescription ambien ambien 10mg poker us levitra free samples do meridia phentermine work the same order celine black shoulder bag louis vuitton patent black sandals over the counter medication cheap 37 5 phentermine safe effective diet pills loewe white handbag dolce gabbana black trainers buying phentermine alprazolam generic for xanax ativan 2mg prada beige fairy l bag generic cialis canadian diet phentermine viagra online cheap europe cialis platinum play bingo levitra info prescription drugs migraines levitra alternative phentermine ingredient how does cialis work louis vuitton damier azure canvas galliera gm order amoxicillin new arthritis and psoriasis drug lipitor online pharmacy professional blackjack how does cialis ultram ingredients