So I’ve written up a fancy little flash program that rotates through swf files.
Much like Blizzard’s world of warcraft site.
What i am trying to do is make sure that my flash file reads from cache and NOT from the server every time, except the first initial onLoad. (to reduce server load).
Here is my code, it is a little rough and messy, but it works beautifully.
/*XML News Rotator - by Benjamin Chu - February 14th, 2008*/
//global variables set
_root.i = 0; //count variable - which element number in the XML gets read
_root.xmlsize = 0; //total size of the XML element at firstChild.childNodes[]
var intervalID;
_root.myIdentifier=Math.round(Math.random()*10000);
//create new XML data structure
xmlData = new XML();
xmlData.ignoreWhite = true;
//Initial load of XML content to variables - only happens once!
this.onLoad = function() {
function loadXML(loaded) { //if loadXML has been loaded...do the following
for (a = 0; a < 20; a++) { //for-loop made to count the total number of xml elements (limit set at 20)
if (this.firstChild.childNodes[a] != undefined) { //
_root.xmlsize++; //iteration for each loop
}
}
if (loaded) { //setting XML values to flash variables
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml?uniq="+_root.myIdentifier); //Path of XML file (URL)
clearInterval(intervalID);
intervalID = setInterval(
function(){
_root.i++;
if (_root.i > _root.xmlsize-1) {
_root.i = 0;
}
function loadXML(loaded) {
if (loaded) {
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
}, 7000);
};
//Button Code for b1
_root.btn_next.onRelease = function() {
_root.i++; //increase iteration - next xml element
if (_root.i > _root.xmlsize-1) { //if statement to keep the program from displaying non-existent xml values
_root.i = 0;
}
function loadXML(loaded) {
if (loaded) {
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
clearInterval(intervalID);
intervalID = setInterval(
function(){
_root.i++;
if (_root.i > _root.xmlsize-1) {
_root.i = 0;
}
function loadXML(loaded) {
if (loaded) {
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
}, 7000);
};
//Button Code for b2
_root.btn_prev.onRelease = function() {
_root.i--;
if (_root.i < 0) {
_root.i = _root.xmlsize-1;
}
function loadXML(loaded) {
if (loaded) {
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
clearInterval(intervalID);
intervalID = setInterval(
function(){
_root.i++;
if (_root.i > _root.xmlsize-1) {
_root.i = 0;
}
function loadXML(loaded) {
if (loaded) {
_root.section = this.firstChild.childNodes[_root.i].childNodes[0].firstChild.nodeValue;
_root.click_url = this.firstChild.childNodes[_root.i].childNodes[1].firstChild.nodeValue;
_root.transition.gotoAndPlay("closing");
} else {
content = "file not loaded!";
}
}
xmlData.onLoad = loadXML;
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
}, 7000);
};
_root.invs_btn.onRelease = function() {
getURL(_root.click_url, "_self");
};
As you can see…I only use this once:
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml?uniq="+_root.myIdentifier);
this will obviously force the flash file to read from server and NOT cache, which is what i want.
but then everywhere else, i use:
xmlData.load("http://www.anime-expo.org/flash/rotator/news.xml");
Will this part above be reading from cache or server?
I want it to read from cache now.
Should i NOT use specific paths? and use relative links? Does that matter?
–
Also within my XML file, i am returning a url path to an external swf file.
_root.section = the url path of the next swf to be loaded
Will these get cached as well? They don’t have any Identifiers.