Posts Tagged ‘URL Request’

How to refresh XML in Flash files

Monday, December 21st, 2009

I have recently been working with loading XML documents in Flash files. This is great technology. The ability to feed dynamic XML data into flash is very powerful and will give you (the designer) a lot of creative freedom. Recently I was using a test XML document in my development environment and altered my XML file. The problem was that every time I re-loaded the file, I was getting the exact same output.

Here is the code that I was using first. Notice that is the same URL.

xmlLoader.load(new URLRequest ("myXMLfile.xml");

Since this file was already cached, it would load over and over again in my output window.

How did I get around this? I added a random query string to the end of URL. I did this by using the Math.random() function built into Flash.

xmlLoader.load(new URLRequest ("myXMLfile.xml?num=" + (Math.random() * 500)));

This little snipped of code will add a random number between 1 and 500 to the end of your query string. You can make the 500 whatever number you want, however I recommend keeping it under 1000.

Hope this helps you!