Flash cachebuster

Posted on 2009-12-24
Last Modified: 2013-11-11
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

Question by:gogetsome
    1 Comment
    LVL 14

    Accepted Solution

    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now