/**
* VERSION: 1.891
* DATE: 2011-11-03
* AS3
* UPDATES AND DOCS AT: http://www.greensock.com/loadermax/
**/
package com.greensock.loading {
import com.greensock.events.LoaderEvent;
import com.greensock.loading.core.LoaderCore;
import flash.events.Event;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.SecurityDomain;
import flash.utils.getTimer;
/** Dispatched when the XML finishes loading and its contents are parsed (creating any dynamic XML-driven loader instances necessary). If any dynamic loaders are created and have a load="true"
attribute, they will begin loading at this point and the XMLLoader's COMPLETE
will not be dispatched until the loaders have completed as well. **/
[Event(name="init", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches an OPEN event. **/
[Event(name="childOpen", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches a PROGRESS event. **/
[Event(name="childProgress", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches a COMPLETE event. **/
[Event(name="childComplete", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches a FAIL event. **/
[Event(name="childFail", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches a CANCEL event. **/
[Event(name="childCancel", type="com.greensock.events.LoaderEvent")]
/** Dispatched when any loader that the XMLLoader discovered in the XML dispatches a SCRIPT_ACCESS_DENIED event. **/
[Event(name="scriptAccessDenied", type="com.greensock.events.LoaderEvent")]
/** Dispatched when the loader's httpStatus
value changes. **/
[Event(name="httpStatus", type="com.greensock.events.LoaderEvent")]
/** Dispatched when the loader experiences a SECURITY_ERROR which can occur when the XML file is loaded from another domain and there is no crossdomain.xml file in place granting appropriate access. **/
[Event(name="securityError", type="com.greensock.events.LoaderEvent")]
/**
* Loads an XML file and automatically searches it for LoaderMax-related nodes like <LoaderMax>,
* <ImageLoader>, <SWFLoader>, <XMLLoader>, <DataLoader> <CSSLoader>, <MP3Loader>
,
* etc.; if it finds any, it will create the necessary instances and begin loading them if they have a load="true"
* attribute. The XMLLoader's progress
will automatically factor in the dynamically-created
* loaders that have the load="true"
attribute and it won't dispatch its COMPLETE
event
* until those loaders have completed as well (unless integrateProgress:false
is passed to the constructor).
* For example, let's say the XML file contains the following XML:
*
* @example Example XML code:
activate()
method for details)
* and it will create instances dynamically. Then it will start loading the ones that had a load="true"
* attribute which in this case means all but the first loader will be loaded in the order they were defined in the XML.
* Notice the loaders nested inside the <LoaderMax>
don't have load="true"
but
* they will be loaded anyway because their parent LoaderMax has the load="true"
attribute.
* After the XMLLoader's INIT
event is dispatched, you can get any loader by name or URL with the
* LoaderMax.getLoader()
method and monitor its progress or control it as you please.
* And after the XMLLoader's COMPLETE
event is dispatched, you can use LoaderMax.getContent()
* to get content based on the name or URL of any of the loaders that had load="true"
defined
* in the XML. For example:
*
* @example Example AS3 code:vars
object of
* the resulting loader as well as an extra rawXML
property which will contain the raw XML
* for that node. For example, if this node is in your XML document: vars
property and create a rawXML
* property there that contains the whole XML node (including the children) so that you can easily get
* whatever data you need like this: vars
* parameter which can be either a generic object or an XMLLoaderVars
object:LoaderMax.getLoader()
or LoaderMax.getContent()
methods or traced at any time. Each loader's name should be unique. If you don't define one, a unique name will be created automatically, like "loader21".<LoaderMax>, <ImageLoader>, <SWFLoader>, <XMLLoader>, <MP3Loader>, <DataLoader>
, and <CSSLoader>
inside the XML when it inits. If it finds any that have a load="true"
attribute, it will begin loading them and integrate their progress into the XMLLoader's overall progress. Its COMPLETE
event won't fire until all of these loaders have completed as well. If you prefer NOT to integrate the dynamically-created loader instances into the XMLLoader's overall progress
, set integrateProgress
to false
.alternateURL
, the loader will initially try to load from its original url
and if it fails, it will automatically (and permanently) change the loader's url
to the alternateURL
and try again. Think of it as a fallback or backup url
. It is perfectly acceptable to use the same alternateURL
for multiple loaders (maybe a default image for various ImageLoaders for example).noCache
is true
, a "gsCacheBusterID" parameter will be appended to the url with a random set of numbers to prevent caching (don't worry, this info is ignored when you getLoader()
or getContent()
by url and when you're running locally)bytesTotal
is set to the estimatedBytes
value (or LoaderMax.defaultEstimatedBytes
if one isn't defined). Then, when the XML has been loaded and analyzed enough to determine the size of any dynamic loaders that were found in the XML data (like <ImageLoader> nodes, etc.), it will adjust the bytesTotal
accordingly. Setting estimatedBytes
is optional, but it provides a way to avoid situations where the progress
and bytesTotal
values jump around as XMLLoader recognizes nested loaders in the XML and audits their size. The estimatedBytes
value should include all nested loaders as well, so if your XML file itself is 500 bytes and you have 3 <ImageLoader> tags with load="true"
and each image is about 2000 bytes, your XMLLoader's estimatedBytes
should be 6500. The more accurate the value, the more accurate the loaders' overall progress will be.requireWithRoot
property to your swf's root
. For example, var loader:XMLLoader = new XMLLoader("data.xml", {name:"data", requireWithRoot:this.root});
autoDispose
is true
, the loader will be disposed immediately after it completes (it calls the dispose()
method internally after dispatching its COMPLETE
event). This will remove any listeners that were defined in the vars object (like onComplete, onProgress, onError, onInit). Once a loader is disposed, it can no longer be found with LoaderMax.getLoader()
or LoaderMax.getContent()
- it is essentially destroyed but its content is not unloaded (you must call unload()
or dispose(true)
to unload its content). The default autoDispose
value is false
.<ImageLoader url="1.jpg" />
and prependURLs
is set to "../images/", then the ImageLoader's url will end up being "../images/1.jpg". prependURLs
affects ALL parsed loaders in the XML. However, if you have an <XMLLoader>
node inside your XML that also loads another XML doc and you'd like to recursively prepend all of the URLs in this loader's XML as well as the subloading one and all of its children, use recursivePrependURLs
instead of prependURLs
.maxConnections
you define.allowMalformedURL:true
. For example, if your URL has duplicate variables in the query string like http://www.greensock.com/?c=S&c=SE&c=SW
, it is technically considered a malformed URL and a URLVariables object can't properly contain all the duplicates, so in this case you'd want to set allowMalformedURL
to true
.skipFailed
to false
(it is true
by default).prependURLs
except that it is recursive, affecting all parsed loaders in subloaded XMLLoaders (other XML files that this one loads too). For example, if your XML has the following node: <XMLLoader url="doc2.xml" />
and recursivePrependURLs
is set to "../xml/", then the nested XMLLoader's URL will end up being "../xml/doc2.xml". Since it is recursive, parsed loaders inside doc2.xml and any other XML files that it loads will all have their URLs prepended. So if you load doc1.xml which loads doc2.xml which loads doc3.xml (due to <XMLLoader>
nodes discovered in each XML file), recursivePrependURLs
will affect all of the parsed LoaderMax-related URLs in all 3 documents. If you'd prefer to only have the URLs affected that are in the XML file that this XMLLoader is loading, use prependURLs
instead of recursivePrependURLs
.
*
* LoaderEvent.OPEN
events which are dispatched when the loader begins loading. Make sure your onOpen function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).XMLLoader.RAW_LOAD
events which are dispatched when the loader finishes loading the XML but has NOT parsed the XML yet. This can be useful in rare situations when you want to alter the XML before it is parsed by XMLLoader (for identifying LoaderMax-related nodes like <ImageLoader>
, etc.). Make sure your onRawLoad function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.INIT
events which are dispatched when the loader finishes loading the XML file, parses its contents, and creates any dynamic XML-driven loaders. If any dynamic loaders are created and have a load="true"
attribute, they will begin loading at this point and the XMLLoader's COMPLETE
will not be dispatched until the loaders have completed as well. Make sure your onInit function accepts a single parameter of type Event
(flash.events.Event).LoaderEvent.PROGRESS
events which are dispatched whenever the bytesLoaded
changes. Make sure your onProgress function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
). You can use the LoaderEvent's target.progress
to get the loader's progress value or use its target.bytesLoaded
and target.bytesTotal
.LoaderEvent.COMPLETE
events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CANCEL
events which are dispatched when loading is aborted due to either a failure or because another loader was prioritized or cancel()
was manually called. Make sure your onCancel function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.ERROR
events which are dispatched whenever the loader experiences an error (typically an IO_ERROR or SECURITY_ERROR). An error doesn't necessarily mean the loader failed, however - to listen for when a loader fails, use the onFail
special property. Make sure your onError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.FAIL
events which are dispatched whenever the loader fails and its status
changes to LoaderStatus.FAILED
. Make sure your onFail function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.IO_ERROR
events which will also call the onError handler, so you can use that as more of a catch-all whereas onIOError
is specifically for LoaderEvent.IO_ERROR events. Make sure your onIOError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.HTTP_STATUS
events. Make sure your onHTTPStatus function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
). You can determine the httpStatus code using the LoaderEvent's target.httpStatus
(LoaderItems keep track of their httpStatus
when possible, although certain environments prevent Flash from getting httpStatus information).LoaderEvent.SECURITY_ERROR
events which onError handles as well, so you can use that as more of a catch-all whereas onSecurityError is specifically for SECURITY_ERROR events. Make sure your onSecurityError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_OPEN
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML begins loading. Make sure your onChildOpen function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_PROGRESS
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML dispatches a PROGRESS
event. To listen for changes in the XMLLoader's overall progress, use the onProgress
special property instead. You can use the LoaderEvent's target.progress
to get the child loader's progress value or use its target.bytesLoaded
and target.bytesTotal
. The LoaderEvent's currentTarget
refers to the XMLLoader, so you can check its overall progress with the LoaderEvent's currentTarget.progress
. Make sure your onChildProgress function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_COMPLETE
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML finishes loading successfully. Make sure your onChildComplete function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_CANCEL
events which are dispatched each time loading is aborted on any nested LoaderMax-related loaders that were defined in the XML due to either an error or because another loader was prioritized in the queue or because cancel()
was manually called on the child loader. Make sure your onChildCancel function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_FAIL
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML fails (and its status
chances to LoaderStatus.FAILED
). Make sure your onChildFail function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).XMLLoaderVars
instance
* instead of a generic object to define your vars
is a bit more verbose but provides
* code hinting and improved debugging because it enforces strict data typing. Use whichever one you prefer.var xml:XML = new XML(myDataLoader.content);
load
is "true"
, the loader will be loaded by the XMLLoader and its progress will be integrated with the XMLLoader's overall progress.prependURLs
. For example, <LoaderMax name="mainQueue" prependURLs="http://www.greensock.com/images/"><ImageLoader url="image1.jpg" /></LoaderMax>
would cause the ImageLoader's url to become "http://www.greensock.com/images/image1.jpg". replaceURLText
. Separate the old value that should be replaced from the new one that should replace it with a comma (","). The list can be as long as you want. For example, <LoaderMax name="mainQueue" replaceURLText="{imageDirectory},http://www.greensock.com/images/,{language},_en"><ImageLoader url="{imageDirectory}image1{language}.jpg" /></LoaderMax>
would cause the ImageLoader's url
to become "http://www.greensock.com/images/image1_en.jpg". childrenVars
and define a comma-delimited list of values like <LoaderMax name="mainQueue" childrenVars="width:200,height:100,scaleMode:proportionalOutside,crop:true"><ImageLoader url="image1.jpg" /><ImageLoader url="image2.jpg" /></LoaderMax>
. Values that are defined directly in one of the child nodes will override any value(s) in the childrenVars, making things very flexible. So if you want the width
of all of the children to be 200 except one which should be 500, just use childrenVars="width:200"
and then in the child that should be 500 pixels wide, set that in the node like <ImageLoader url="1.jpg" width="500" />
(new in version 1.88)<SWFLoader>
loaders. It defines the LoaderContext's ApplicationDomain (see Adobe's LoaderContext
docs for details). "child"
is the default.content
data type: XML
<ImageLoader>
, etc.) **/
public static var RAW_LOAD:String = "rawLoad";
/** @private contains only the parsed loaders that had the load="true" XML attribute. It also contains the _parsed LoaderMax which is paused, so it won't load (we put it in there for easy searching). **/
protected var _loadingQueue:LoaderMax;
/** @private contains all the parsed loaders (String
) or URLRequest
from which the loader should get its content.
* @param vars An object containing optional configuration details. For example: new XMLLoader("xml/data.xml", {name:"data", onComplete:completeHandler, onProgress:progressHandler})
.vars
parameter
* which can be either a generic object or an XMLLoaderVars
object:LoaderMax.getLoader()
or LoaderMax.getContent()
methods or traced at any time. Each loader's name should be unique. If you don't define one, a unique name will be created automatically, like "loader21".<LoaderMax>, <ImageLoader>, <SWFLoader>, <XMLLoader>, <MP3Loader>, <DataLoader>
, and <CSSLoader>
inside the XML when it inits. If it finds any that have a load="true"
attribute, it will begin loading them and integrate their progress into the XMLLoader's overall progress. Its COMPLETE
event won't fire until all of these loaders have completed as well. If you prefer NOT to integrate the dynamically-created loader instances into the XMLLoader's overall progress
, set integrateProgress
to false
.alternateURL
, the loader will initially try to load from its original url
and if it fails, it will automatically (and permanently) change the loader's url
to the alternateURL
and try again. Think of it as a fallback or backup url
. It is perfectly acceptable to use the same alternateURL
for multiple loaders (maybe a default image for various ImageLoaders for example).noCache
is true
, a "gsCacheBusterID" parameter will be appended to the url with a random set of numbers to prevent caching (don't worry, this info is ignored when you getLoader()
or getContent()
by url and when you're running locally)bytesTotal
is set to the estimatedBytes
value (or LoaderMax.defaultEstimatedBytes
if one isn't defined). Then, when the XML has been loaded and analyzed enough to determine the size of any dynamic loaders that were found in the XML data (like <ImageLoader> nodes, etc.), it will adjust the bytesTotal
accordingly. Setting estimatedBytes
is optional, but it provides a way to avoid situations where the progress
and bytesTotal
values jump around as XMLLoader recognizes nested loaders in the XML and audits their size. The estimatedBytes
value should include all nested loaders as well, so if your XML file itself is 500 bytes and you have 3 <ImageLoader> tags with load="true"
and each image is about 2000 bytes, your XMLLoader's estimatedBytes
should be 6500. The more accurate the value, the more accurate the loaders' overall progress will be.requireWithRoot
property to your swf's root
. For example, var loader:XMLLoader = new XMLLoader("data.xml", {name:"data", requireWithRoot:this.root});
autoDispose
is true
, the loader will be disposed immediately after it completes (it calls the dispose()
method internally after dispatching its COMPLETE
event). This will remove any listeners that were defined in the vars object (like onComplete, onProgress, onError, onInit). Once a loader is disposed, it can no longer be found with LoaderMax.getLoader()
or LoaderMax.getContent()
- it is essentially destroyed but its content is not unloaded (you must call unload()
or dispose(true)
to unload its content). The default autoDispose
value is false
.<ImageLoader url="1.jpg" />
and prependURLs
is set to "../images/", then the ImageLoader's url will end up being "../images/1.jpg". prependURLs
affects ALL parsed loaders in the XML. However, if you have an <XMLLoader>
node inside your XML that also loads another XML doc and you'd like to recursively prepend all of the URLs in this loader's XML as well as the subloading one and all of its children, use recursivePrependURLs
instead of prependURLs
.maxConnections
you define.allowMalformedURL:true
. For example, if your URL has duplicate variables in the query string like http://www.greensock.com/?c=S&c=SE&c=SW
, it is technically considered a malformed URL and a URLVariables object can't properly contain all the duplicates, so in this case you'd want to set allowMalformedURL
to true
.skipFailed
to false
(it is true
by default).prependURLs
except that it is recursive, affecting all parsed loaders in subloaded XMLLoaders (other XML files that this one loads too). For example, if your XML has the following node: <XMLLoader url="doc2.xml" />
and recursivePrependURLs
is set to "../xml/", then the nested XMLLoader's URL will end up being "../xml/doc2.xml". Since it is recursive, parsed loaders inside doc2.xml and any other XML files that it loads will all have their URLs prepended. So if you load doc1.xml which loads doc2.xml which loads doc3.xml (due to <XMLLoader>
nodes discovered in each XML file), recursivePrependURLs
will affect all of the parsed LoaderMax-related URLs in all 3 documents. If you'd prefer to only have the URLs affected that are in the XML file that this XMLLoader is loading, use prependURLs
instead of recursivePrependURLs
.
*
* LoaderEvent.OPEN
events which are dispatched when the loader begins loading. Make sure your onOpen function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).XMLLoader.RAW_LOAD
events which are dispatched when the loader finishes loading the XML but has NOT parsed the XML yet. This can be useful in rare situations when you want to alter the XML before it is parsed by XMLLoader (for identifying LoaderMax-related nodes like <ImageLoader>
, etc.). Make sure your onRawLoad function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.INIT
events which are dispatched when the loader finishes loading the XML file, parses its contents, and creates any dynamic XML-driven loaders. If any dynamic loaders are created and have a load="true"
attribute, they will begin loading at this point and the XMLLoader's COMPLETE
will not be dispatched until the loaders have completed as well. Make sure your onInit function accepts a single parameter of type Event
(flash.events.Event).LoaderEvent.PROGRESS
events which are dispatched whenever the bytesLoaded
changes. Make sure your onProgress function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
). You can use the LoaderEvent's target.progress
to get the loader's progress value or use its target.bytesLoaded
and target.bytesTotal
.LoaderEvent.COMPLETE
events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CANCEL
events which are dispatched when loading is aborted due to either a failure or because another loader was prioritized or cancel()
was manually called. Make sure your onCancel function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.ERROR
events which are dispatched whenever the loader experiences an error (typically an IO_ERROR or SECURITY_ERROR). An error doesn't necessarily mean the loader failed, however - to listen for when a loader fails, use the onFail
special property. Make sure your onError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.FAIL
events which are dispatched whenever the loader fails and its status
changes to LoaderStatus.FAILED
. Make sure your onFail function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.IO_ERROR
events which will also call the onError handler, so you can use that as more of a catch-all whereas onIOError
is specifically for LoaderEvent.IO_ERROR events. Make sure your onIOError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.HTTP_STATUS
events. Make sure your onHTTPStatus function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
). You can determine the httpStatus code using the LoaderEvent's target.httpStatus
(LoaderItems keep track of their httpStatus
when possible, although certain environments prevent Flash from getting httpStatus information).LoaderEvent.SECURITY_ERROR
events which onError handles as well, so you can use that as more of a catch-all whereas onSecurityError is specifically for SECURITY_ERROR events. Make sure your onSecurityError function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_OPEN
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML begins loading. Make sure your onChildOpen function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_PROGRESS
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML dispatches a PROGRESS
event. To listen for changes in the XMLLoader's overall progress, use the onProgress
special property instead. You can use the LoaderEvent's target.progress
to get the child loader's progress value or use its target.bytesLoaded
and target.bytesTotal
. The LoaderEvent's currentTarget
refers to the XMLLoader, so you can check its overall progress with the LoaderEvent's currentTarget.progress
. Make sure your onChildProgress function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_COMPLETE
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML finishes loading successfully. Make sure your onChildComplete function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_CANCEL
events which are dispatched each time loading is aborted on any nested LoaderMax-related loaders that were defined in the XML due to either an error or because another loader was prioritized in the queue or because cancel()
was manually called on the child loader. Make sure your onChildCancel function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).LoaderEvent.CHILD_FAIL
events which are dispatched each time any nested LoaderMax-related loaders that were defined in the XML fails (and its status
chances to LoaderStatus.FAILED
). Make sure your onChildFail function accepts a single parameter of type LoaderEvent
(com.greensock.events.LoaderEvent
).
*
* var xmlLoader:XMLLoader = new XMLLoader("xml/doc.xml", {name:"xmlDoc", onComplete:completeHandler});
* function completeHandler(event:Event):void {
* var imgLoader:ImageLoader = xmlLoader.getLoader("imageInXML") as ImageLoader;
* addChild(imgLoader.content);
* }
*
* The static LoaderMax.getLoader()
method can be used instead which searches all loaders.
*
* @param nameOrURL The name or url associated with the loader that should be found.
* @return The loader associated with the name or url. Returns null
if none were found.
*/
public function getLoader(nameOrURL:String):* {
return (_parsed != null) ? _parsed.getLoader(nameOrURL) : null;
}
/**
* Finds a particular loader's content
from inside any loaders that were dynamically
* generated based on the xml data. For example:
*
* var loader:XMLLoader = new XMLLoader("xml/doc.xml", {name:"xmlDoc", onComplete:completeHandler});
* function completeHandler(event:Event):void {
* var subloadedImage:Bitmap = loader.getContent("imageInXML");
* addChild(subloadedImage);
* }
*
* The static LoaderMax.getContent()
method can be used instead which searches all loaders.
*
* @param nameOrURL The name or url associated with the loader whose content should be found.
* @return The content associated with the loader's name or url. Returns null
if none were found.
* @see #content
*/
public function getContent(nameOrURL:String):* {
if (nameOrURL == this.name || nameOrURL == _url) {
return _content;
}
var loader:LoaderCore = this.getLoader(nameOrURL);
return (loader != null) ? loader.content : null;
}
/**
* Returns and array of all LoaderMax-related loaders (if any) that were found inside the XML.
* For example, if the following XML was in the document, a child loader would be created for it
* immediately before the INIT event is dispatched:
*
* <ImageLoader url="1.jpg" name="image1" />
*
* Don't forget to use LoaderMax.activate()
to activate the types of loaders
* that you want XMLLoader to recognize (you only need to activate() them once in your swf).
* Like LoaderMax.activate([ImageLoader, SWFLoader]);
to ensure that XMLLoader
* recognizes <ImageLoader> and <SWFLoader> nodes. true
, loaders that are nested inside child LoaderMax, XMLLoader, or SWFLoader instances will be included in the returned array as well. The default is false
.
* @param omitLoaderMaxes If true
, no LoaderMax instances will be returned in the array; only LoaderItems like ImageLoaders, XMLLoaders, SWFLoaders, MP3Loaders, etc. The default is false
.
* @return An array of loaders.
*/
public function getChildren(includeNested:Boolean=false, omitLoaderMaxes:Boolean=false):Array {
return (_parsed != null) ? _parsed.getChildren(includeNested, omitLoaderMaxes) : [];
}
//---- STATIC METHODS ------------------------------------------------------------------------------------
/** @private **/
protected static function _parseVars(xml:XML):Object {
var v:Object = {rawXML:xml};
var s:String, type:String, value:String, domain:ApplicationDomain;
var list:XMLList = xml.attributes();
for each (var attribute:XML in list) {
s = attribute.name();
value = attribute.toString();
if (s == "url") {
continue;
} else if (s == "context") {
v.context = new LoaderContext(true,
(value == "own") ? ApplicationDomain.currentDomain : (value == "separate") ? new ApplicationDomain() : new ApplicationDomain(ApplicationDomain.currentDomain),
(!_isLocal) ? SecurityDomain.currentDomain : null);
continue;
}
type = typeof(_varTypes[s]);
if (type == "boolean") {
v[s] = Boolean(value == "true" || value == "1");
} else if (type == "number") {
v[s] = Number(value);
} else {
v[s] = value;
}
}
return v;
}
/**
* Parses an XML object and finds all activated loader types (like LoaderMax, ImageLoader, SWFLoader, DataLoader,
* CSSLoader, MP3Loader, etc.), creates the necessary instances, and appends them to the LoaderMax that is defined
* in the 2nd parameter. Don't forget to make sure you activate()
the necessary loader types that you
* want XMLLoader to recognize in the XML, like:
*
* LoaderMax.activate([ImageLoader, SWFLoader]); //or whatever types you're using.
*
* @param xml The XML to parse
* @param all The LoaderMax instance to which all parsed loaders should be appended
* @param toLoad The LoaderMax instance to which ONLY parsed loaders that have a load="true"
attribute defined in the XML should be appended. These loaders will also be appended to the LoaderMax defined in the all
parameter.
*/
public static function parseLoaders(xml:XML, all:LoaderMax, toLoad:LoaderMax=null):void {
var node:XML;
var nodeName:String = String(xml.name()).toLowerCase();
if (nodeName == "loadermax") {
var queue:LoaderMax = all.append(new LoaderMax(_parseVars(xml))) as LoaderMax;
if (toLoad != null && queue.vars.load) {
toLoad.append(queue);
}
if (queue.vars.childrenVars != null && queue.vars.childrenVars.indexOf(":") != -1) {
queue.vars.childrenVars = _parseVars( new XML("