Jump to content


noCache=true for XML and noCache=false for LoaderMax-related in XML

Recommended Posts

Dear colleagues,


Could you help me with noCache please?

I try to do unCached (noCache:true) XML file loading, but with caching loading data from the XML (noCache:false).


On server I have XML file

<?xml version="1.0" encoding="iso-8859-1"?>
 <LoaderMax name="n" prependURLs="www" load="true" noCache="false">
 <ImageLoader url="1.jpg" name="im1" noCache="false"/>
 <ImageLoader url="2.jpg" name="im2" noCache="false"/>


and AS3 code:

var loader:XMLLoader  = new XMLLoader("xmldata.xml",

function ChangeCacheParam(event:LoaderEvent):void{
 loader.vars.noCache =false;

 var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();


But after many experiments of images uploading they are cached (url with gsCacheBusterID=134...).

May be some one have solved this problem or may be I have error in my code.


Thank you in advance for your help,


Link to comment
Share on other sites

I see that you are creating an ImageLoaderVars object and also setting a noCache property to those vars.


You also need to apply that ImageLoaderVars obj to the ImageLoaders that should use those new vars.


Let us know if you need help with that.

Link to comment
Share on other sites

Dear carl schooff,


Thank you for the advice, but I have received the same result :(

image uploading with unCached (gsCacheBusterID=134...)


the last variant of code:


var loader:XMLLoader  = new XMLLoader("xmldata.xml",

var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();
loader.vars.ImageLoaderVars = imageLoaderVars;


may be there is a mistake in applying of ImageLoaderVars in my code?

Link to comment
Share on other sites

yes you will need to change how you are applying the vars.


You would need to do something like:

LoaderMax.getLoader("im1").vars = imageLoaderVars


I will be able to verify that or assist you more in an hour or so.



Link to comment
Share on other sites

update: I just realized you don't want to approach it this way.


onRawLoad fires BEFORE the xml is processed and the ImageLoaders are created. You can't change the vars on the ImageLoader's until they are created. At the point that onRawLoad fires you would need to literally overwrite the <ImageLoader> nodes in the xml.


I'll let you know if I find a solution.

Link to comment
Share on other sites

Turns out I was right that I was wrong :-P

If you use the onInit callback of the XMLLoader to create ImageLoaderVars you will be in good shape.


I created an example which loads 2 images.

both images have noCache = false in the xml:


 <LoaderMax name="n" load="true">
 <ImageLoader url="1.jpg" name="im1" noCache="false" estimatedBytes="3000"/>
 <ImageLoader url="2.jpg" name="im2" noCache="false" estimatedBytes="3000"/>


note I'm using estimatedBytes to prevent a filesize audit. I removed noCache="true" from the LoaderMax node. It doesn't belong there.


When the XMLLoader fires its onInit I then create an ImageLoaderVars object with noCache(true) and apply it to the first ImageLoader.



import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.*;
import com.greensock.loading.data.*;


var loader:XMLLoader  = new XMLLoader("xmldata.xml",{noCache:true, onRawLoad:onRawLoadHandler, onInit:onInitHandler, onComplete:onXMLComplete});

function onXMLComplete(e:LoaderEvent):void{
trace("xml and images loaded");

//use on onInit to access the ImageLoaders that are created from the <ImageLoader> nodes in the xml after they are created, but before they are loaded;
function onInitHandler(e:LoaderEvent):void{
trace(e.target.content); //output the xml
var firstImageLoader:ImageLoader = LoaderMax.getLoader("im1");
trace("onInit find loader im1 : " + firstImageLoader); //works
trace("im1.vars.noCache = " + firstImageLoader.vars.noCache); //output false

var imageLoaderVars:ImageLoaderVars = new ImageLoaderVars();
trace("apply new ImageLoaderVars");
firstImageLoader.vars = imageLoaderVars;
trace("im1.vars.vars.noCache = " + firstImageLoader.vars.vars.noCache); //output true

function onRawLoadHandler(event:LoaderEvent):void{
trace("onRawLoad find loader im1 : " + LoaderMax.getLoader("im1")); //null the ImageLoader hasn't been created yet!


If you run this locally and follow the traces the important thing to note is that noCache is originally false for the first ImageLoader when the XML is first processed but gets set to false before it loads.


You can see it in action here:



Note the images aren't placed on the stage so there is nothing to see in the swf. If you open up the dev console in Chrome (or safari) and switch to the network tab you will be able to see that


1.jpg has the gsCachBusterID applied

2.jpg does not




*note reload the page after the "network" tab is visible.



I attached a zip of all my files (CS5) so you can test the traces locally. Keep in mind the gsCacheBuster ONLY gets applied when the swf is running remotely.


Link to comment
Share on other sites

Dear Carl Schooff,


Many thanks, for your the detailed help/answer !


For my colleagues ...

if you like to set noCache="false" in XML, you have to set estimatedBytes.

In other case noCache="false" will be ignored.

Link to comment
Share on other sites

Hi Vlad,


Very glad you have made progress.


Just to be clear,


Setting the estimatedBytes only prevents LoaderMax from auditing the filesize. When LoaderMax performs an audit it downloads just enough of the file to get the total file size so that it can more accurately track the cumulative progress of multiple loaders. By telling LoaderMax how big the file is (estimatedBytes) it knows not to do the audit.


You can use noCache regardless of whether or not an audit takes place. When an audit takes place the url of the file always has the gsCacheBusterID appended to make sure it is getting the most accurate and recent file size. (http://forums.greens...0497#entry20497)


You can read more about audits in section 9 and 10 of http://www.greensock...loadermax-tips/ and in various parts of the documentation.


If you look in the Chrome dev tools or firebug and see 2 downloads of each asset, remember that one of them is the audit and the other is the full download.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.