My flash XMLbillboard - odd behaviour when online, setIntervals wrong?

Hello forum!

This is my last resort as I bang my head on the desk over and over, trying to find out why my flash XMLbillboard works fine locally, but then behaves all wack when posted online. If any script gurus can spare some time to clean up my code or tell me where I’ve gone wrong, it would be greatly appreciated! ((>_<))

It appears my code works (not hard to tell it was coded by a designer!) but I’m sure there are a couple of hiccups that are causing problems when uploaded to the server. I think it has something to do with the setInterval() calls, so if there are better methods to use, please let me know.

Essentially, it’s a simple cross-fading slideshow which reads the scenes in from an XML file and begins the show. The idea is to be able to jump to the next, previous, or other scenes in the XML file by clicking the item buttons. The XML source path and starting node can be changed by passing in the XMLsrc and XMLid params from the HTML object (“XMLbillboard.swf?XMLsrc=foo.xml&XMLid=n”)

To demonstrate the wackness, here the board appears to work fine:
http://www.scopebi.com.au/scopebi/
XMLsrc:
[color=#003366]http://www.scopebi.com.au/scopebi/assets/swf/images.xml[/color]

The problematic page in question is this:
http://www.scopebi.com.au/scopebi/products/
XMLsrc:
http://www.scopebi.com.au/scopebi/assets/swf/products.xml

Same flash movie, different XML files. I’ll paste the entire block of Actionscript below…


//////////////////////////////////////////////////////////////////////////////////////////////
// XMLbillboard by Vaughan James of [www.reality-engine.com](http://www.reality-engine.com/)
// crossfading slide show orignally by Todd Dominey of [www.domineydesign.com](http://www.domineydesign.com/)
 
//////////////////////////////////////////////////////////////////////////////////////////////
// setup the initial variables
debug = true; // display debugging and error output
 
// find the XMLsrc path and XMLid start node. these vars are passed to the movie from HTML page where the flash object...
// eg. <param name="movie" value="/XMLbillboard.swf?XMLsrc=/assets/swf/datafile.xml&XMLid=n" /> 
// where n is the starting scene. regardless of setting 'random' or 'sequential' order in the XML file, 
// this will be the first scene shown, then the scene will progress as per the order set in the XML file.
 
function ignition(){
// load mathematical tweening script 
#include "tween.as"
if (XMLsrc == null){
XMLsrc = "products.xml";
}
if (XMLid == null){
XMLid = 0;
}
 
 
// load xml
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;
images_xml.load(XMLsrc);
 
trace("...ignition! start at scene [ "+XMLid+" ]");
trace("//////////////////////////////////////////////////////////////////////////////////////////////////"+newline); 
 
}
ignition();
 
//////////////////////////////////////////////////////////////////////////////////////////////
// set random # variables - each must be 0 for first 'while' loop below
// var randomNum = 0;
// var randomNumLast = 0;
 
// parent container
var container_mc = this.createEmptyMovieClip("container",0);
_root.attachMovie("roundmask","roundmask_mc", 101);
container_mc.setMask("roundmask_mc");
 
// movie clip containers
container_mc.createEmptyMovieClip("loader1_mc",2);
container_mc.createEmptyMovieClip("loader2_mc",1);
 
// preload watcher
this.createEmptyMovieClip("watcher_mc",100);
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// process the xml data
function parse(success) {
if (success) {
trace("parsing XML data from [ " +XMLsrc+ " ]");
imageArray = new Array();
var root = this.firstChild;
//_global.numPause = Number(this.firstChild.attributes.timer * 1000); // second
_global.order = this.firstChild.attributes.order;
_global.looping = this.firstChild.attributes.looping;
_global.fadetime = Number(this.firstChild.attributes.fadetime); // seconds
_global.xpos = Number(this.firstChild.attributes.xpos);
_global.ypos = Number(this.firstChild.attributes.ypos);
var imageNode = root.lastChild;
var s = 0;
while (imageNode.nodeName != null) {
imageData = new Object;
imageData.path = imageNode.attributes.path;
imageData.timer = imageNode.attributes.timer;
imageArray[s] = imageData;
trace("imageArray["+s+"] imageData.path [ "+imageData.path+" ] imageData.timer [ "+imageData.timer+" ]");
imageNode = imageNode.previousSibling;
s++;
}
trace("XML parsed succesfully");
trace("//////////////////////////////////////////////////////////////////////////////////////////////////"+newline);
 
// parse array
imageArray.reverse();
// move the image container onto stage
placeContainer();
 
} else {
trace("problem loading XML data from [ " + XMLsrc + " ]");
errorOutput("Problem loading XML data from [ " + XMLsrc + " ]");
}
}
function placeContainer(){
// setup default start values for the image container. 
// eg. off stage, then slide into view when the scene has loaded
container_mc._x = _global.xpos;
container_mc._y =_global.ypos; 
// create a menu based on the number of nodes in the XML
makeMenu();
}
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// create a menu item for each xml node
function makeMenu() {
// make sure the menu is on top
_root.navigation.swapDepths(container_mc);
menuItem = images_xml.firstChild.childNodes;
var hgap = 5;	// horizontal space between items
var start_x = 25; // horizontal position of first item (push it past btn_prev to prevent overlap)
var start_y = 0; // vertical position of all items in the navigation bar
for (var i=0; i<menuItem.length; i++) {
item = _root.navigation.attachMovie("itembox", "itembox" + i, i+9999);
item._x = start_x + ((item._width+hgap)*i); 
item._y = start_y;
item.myKey = i;
item.itemLabel = menuItem*.attributes.name;
item.myUrl = menuItem*.attributes.url;
 
trace("item [ "+item+" ] name [ "+item.itemLabel+" ] url [ "+item.myUrl+" ]");
 
// this little routine strips the 0 from the display (first scene = 0 shows up as scene 1) 
// scene items less than 10 are shown as double digits or you can append other chars to each item
if(i < 9){ 
item.txt_itemnum.text ="0"+(i+1);
}else{
item.txt_itemnum.text = i+1;
}
 
item.onRollOut = function() {
_root.navigation.itemLabel.text = "";
this.txt_itemnum.cOut = new Color(this.txt_itemnum);
this.txt_itemnum.cOut.setRGB(0xDDDDDD);
}
item.onRollOver = function() {
//trace(this+" rollOver");
_root.navigation.itemLabel.text = this.itemLabel;//"foo";
this.txt_itemnum.cHover = new Color(this.txt_itemnum);
this.txt_itemnum.cHover.setRGB(0x0071AD); 
}
item.onRelease = function() {
trace(this+".onRelease called"); 
var num = this.myKey; // the index or id to use
trace(this+" onRelease [ "+num+" ]");
this.txt_itemnum.cActive = new Color(this.txt_itemnum);
this.txt_itemnum.cActive .setRGB(0xFFFFFF);
sceneNumber(num,"jump");
//getURL(this.myUrl,"_blank");
}
last_item = item._x;
}
trace("menu parsed successfully from [ "+XMLsrc+" ]");
trace("//////////////////////////////////////////////////////////////////////////////////////////////////"+newline);
// place the next button after the last menu item
var last_posi = last_item + item._width + btn_prev._width + hgap;
//trace("last_item _x is at [ "+last_item+" ] and last_posi [ "+last_posi+" ]");
_root.btn_next._x = last_posi;
 
scene_num = XMLid;
sceneNumber(scene_num,"start");
};
 
//////////////////////////////////////////////////////////////////////////////////////////
// button routines
_root.btn_prev.onRelease = function(){
trace(this+" onRelease [ -1 ]");
sceneNumber(-1,"next");
}
_root.btn_next.onRelease = function(){
trace(this+" onRelease [ +1 ]");
sceneNumber(1,"next");
}
 
//////////////////////////////////////////////////////////////////////////////////////////
// watch for scene id changes (do something if the scene is changed)
function highlightScene(){
curr_node.text = scene_num;
	 // trace("scene_num is [ "+scene_num+" ]");
for (var scene_n = 0; scene_n <= 20; scene_n++){ // set all items to default state or colour
mc=eval("_root.navigation.itembox"+scene_n+".txt_itemnum");
mc.hover = new Color(mc);
mc.hover.setRGB(0xDDDDDD);
if(scene_n == scene_num){ // select the scene item if the current scene matches
	mc.hover = new Color(mc);
	mc.hover.setRGB(0x0071AD);
}
}
};
//import mx.utils.Delegate; // removed for flash player 7 compatability
//clearInterval(eachsecond);
eachsecond = setInterval(this, "highlightScene", 1000);
 
//////////////////////////////////////////////////////////////////////////////////////////
// scene number handling
function sceneNumber(num,jump){
 
scene_curr = scene_num;
trace(newline+"current scene is [ "+scene_curr+" ]");
_global.scene_min = 0;
_global.scene_max = menuItem.length - 1;
 
switch (jump){
case "start":
trace("///// start [ "+num+" ]"+newline);
loadImages(imageArray,num);
break;
 
case "jump":
trace("///// jump [ "+num+" ]"+newline);
scene_next = num;
if(scene_curr != scene_next){
	loadImages(imageArray,num);
	scene_num = scene_next;
}
break;
 
case "next":
trace("///// next [ "+num+" ]"+newline);
scene_next = scene_curr + num;
if(scene_next >= scene_min && scene_next <= scene_max){
	trace("next scene [ " +scene_next+" ] okay"); 
	scene_num = scene_next;
	loadImages(imageArray,scene_next);
}else{
	trace("next scene [ " +scene_next+" ] out of bounds");
	if(scene_next <= scene_min){
	 trace("stopped at first scene [ "+scene_min+" ]");
	}else if(scene_next >= scene_max){
	 trace("stopped at last scene [ "+scene_max+" ]");
	}
}
break;
 
}
};
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// loading routines
function loadImages(data,num) {
// create the image preloader if the scene changes
if (i==undefined || i == 2) {
i=2;
createLoader(i,data,num);
i=1;
} else if (i==1) {
createLoader(i,data,num);
i=2;
}
// end 
};
// depth swapping
function swapPlace(clip,num) {
eval(clip).swapDepths(eval("container_mc.loader"+num+"_mc"));
}
function createLoader(i,data,num) {
var filename = data[num].path; 
var timer = data[num].timer; 
trace("[ depth ] is [ "+i+" ]");
trace("[ data ] is [ "+data+" ]");
trace("[ num ] is [ "+num+" ]");
trace("[ filename ] is [ "+filename+" ]");
trace("[ timer ] is [ "+timer+" ] seconds");
_global.numPause = timer;
 
thisLoader = eval("container_mc.loader"+i+"_mc");
thisLoader._alpha = 0;
thisLoader.loadMovie(filename);
watcher_mc.onEnterFrame=function () { 
var picLoaded = thisLoader.getBytesLoaded();
var picBytes = thisLoader.getBytesTotal();
picPercent = Math.round(100 * (picLoaded / picBytes));
errorOutput("[ " +filename+" ] loading... [ "+picLoaded+" ] bytes of [ "+picBytes+" ] loaded [ "+picPercent+"% ]");
preloaderOutput(picPercent);
if (isNaN(picBytes) || picBytes < 4) {
return;
}
if (picLoaded / picBytes >= 1) {
trace("[ " +filename+" ] loaded");
swapPlace("container_mc.loader2_mc",1); 
thisLoader.tween("_alpha", 100, _global.fadetime, "easeoutsine", 0);
delete this.onEnterFrame;	 
// pause the scene
pauseScene(_global.numPause);
}
};
};
function pauseScene(delay){
clearInterval(_global.timedelay);
trace("///// pause for [ "+numPause+" ] seconds");
 
var tic = 0;	 // start from zero
var max_count = delay; // seconds to count
var duration = 1000; // milliseconds (1000 = seconds)
// set the format for display text
createTextField("txt_preloaderOutput", 888, Stage.width - 210, Stage.height - 20, 200, 20);
 
txt_pauseFormat = new TextFormat();
txt_pauseFormat.font = "Arial";
txt_pauseFormat.size = 10;
txt_pauseFormat.bold= false;
txt_pauseFormat.color = 0xCCCCCC;
txt_pauseFormat.align = "right"; 
pausetimer = function() {
var countdown = _global.numPause - tic;
var showthis = countdown + " seconds";
trace("pausetimer [ " + timedelay + " ] tic [ " + tic+" ] countdown [ "+countdown+" ] seconds");
 
if(tic >= max_count) {
clearInterval(_global.timedelay);
showthis = countdown + " seconds";
trace("timedelay [ " + timedelay + " ] cleared");
sceneNumber(1,"next"); 
} 
tic++;
 
txt_preloaderOutput.text = showthis;
txt_preloaderOutput.selectable = false;
txt_preloaderOutput.setTextFormat(txt_pauseFormat);
}
_global.timedelay = setInterval(this, "pausetimer", duration);
};
// display preloader output to player
function preloaderOutput(data){
// set the format for display text
txt_preloadFormat = new TextFormat();
txt_preloadFormat.font = "Arial";
txt_preloadFormat.size = 50;
txt_preloadFormat.bold= false
txt_preloadFormat.color = 0xCCCCCC;
txt_preloadFormat.align = "left";
 
_root.createTextField("txt_preloaderOutput", 888, 20, 180, 100, 100);
txt_preloaderOutput.selectable = false;
txt_preloaderOutput.text = data + "%";
txt_preloaderOutput.setTextFormat(txt_preloadFormat);
 
if( isNaN(data) || data == 0 || data == 100){
clearInterval(_global.timedelay);
txt_preloaderOutput._visible = false;
}else{
txt_preloaderOutput._visible = true; 
} 
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// display error output to player
function errorOutput(data){
// set the format for display text
txt_errorFormat = new TextFormat();
txt_errorFormat.font = "_sans";
txt_errorFormat.size = 9;
txt_errorFormat.color = 0x666666;
txt_errorFormat.align = "left";
 
if (debug == true){
_root.createTextField("txt_errorOutput", 999, 10, 10, Stage.width - 10, 20);
txt_errorOutput.multiline = true;
txt_errorOutput.selectable = false;
txt_errorOutput.text = data;
txt_errorOutput.setTextFormat(txt_errorFormat);
}
};
//////////////////////////////////////////////////////////////////////////////////////////
// stop this timeline from looping
this.stop();
 

It’s a truckload, I apologise - my code isn’t the most efficient or the most elegant, but I’m rapidly losing patience for actionscript and can’t bear to bash my head on the desk any longer.

Can anyone please help spot the problems so I can fix this billboard once and for all? I’d like to target the flash 7 player, but if I have to target for ver 8, then so be it.

Thankyou!

Vaughan aka Stress