Flash cachebuster

Hello, I'm new to flash and have to modify some actionscript to ensure the latest version of the flash object is loaded instead of pulling from the users cache. I have seen that I could do something like this:

images_xml.load("images.xml?cachebuster=" + new Date().getTime());

and that would ensure the users get the latest version. Is that correct??

If so, the actionscript that I need to modify has an init function. I believe that is the correct function to retrieve and load the xml file. Below is the function: how can it me modified to bust that cache???

function init(e:Event) {
			removeEventListener(Event.ENTER_FRAME, init);
			xmlURL = root.loaderInfo.parameters.xmlURL || 'flashbar_Default.xml';

Open in new window

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

TanLiHaoConnect With a Mentor Commented:
I can see that you are using FlashVars. Therefore this should be somehow the correct code you need to modify, assuming the xmlURL used here will be passed to used for loading. This is definitely AS3 so if you see

new URLRequest(xmlURL), then follow my instructions below.

Otherwise, please show me the code in initComponents and initEventHandlers.

OK, the SWF must be embedded in a page and passed the correct xmlURL for this to work properly.

This line of code

 xmlURL = root.loaderInfo.parameters.xmlURL || 'flashbar_Default.xml';

simply means if the xmlURL exists, use it, otherwise use flashbar_Default.xml.

That will get the xml from the cache if no FlashVars is specified, therefore you have to be careful.

Make sure the FlashVars change from flashbar_Default.xml?ver=1 everytime the xml changes.

Do not use random to achieve that, because no matter how random things can be(which is not in this case, this is pseudo-randomness, I won't go into more detail about thtat). People may end up getting the same random number, therefore only change the number when the XML is changed.

For example, everytime your xml is changed

flashbar_Default.xml?ver=1  will become

and so on

You can use it in many formats, but it's your choice. You can also make sure no caching happen but that's a bad way to do it since everytime the user reloads the XML, it wastes your bandwidth.

To summarise, if you want your FlashVars to control the XML with the not reloading of cache, make sure it has a random number behind or use version control to increment like the example I show you. Otherwise, use Flash to control the version.

For example, if you your xmlURL already contains a random number like


Then your line of code you need to modify is

xmlURL = root.loaderInfo.parameters.xmlURL || 'flashbar_Default.xml';

Change it to
var version:Number = 1;
xmlURL = root.loaderInfo.parameters.xmlURL || ('flashbar_Default.xml?ver=' + version);

The version might be changed everytime you edit the xml, or load it from somewhere else or whatever you want.

Otherwise, if your flashbar_Default.xml is passed as flashbar_Default.xml without random numbers behind or version control.

Then you simply change

var version:Number = 1;
xmlURL = (root.loaderInfo.parameters.xmlURL || 'flashbar_Default.xml') + "?ver=" + version;

The above already explained what the version variable is for.
All Courses

From novice to tech pro — start learning today.