Actionscript - random images problem

([FMX04] problem)
Hi,
I have been messing around with various actionscript I found online for the last week but still can’t seem to get working what i need.

I have two versions at the moment as follows:

  1. Flash (with actionscripting) randomly load images from an external XML file.

  2. Flash (with actionscripting) passes variables via HTML page to randomly load images.

Number 1 works, number 2 doesnt. The code is pretty similar, however instead of using the XML file I’m trying to pass the variables using flashvars in the HTML code.

Working version: http://new.stralia.com.au/bourgies/flash/flash1.html (currently a 20 second delay before change of image)
Actionscript from 1:

/define two arrays, fill the “main” array with the instance names of the moieclips on the stage./
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“images.xml”);
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
trace(“total=” + total);
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
trace(“p=”+(i+1));
eval(“p”+(i+1)).loadMovie(image*);
trace(“image=”+image*);
}

main = [p1, p2, p3, p4];
side = [];
//define space to keep track of the last visible item.
nowVisible = {};

//make every mc in the array invisible
for(var i=1; i<main.length; i++){
//main*._visible=false;
main*._alpha=0;
}

}
}

//define a shuffle prototype.
Array.prototype.skuffle = function(){
var toReturn = [];
for(var i=0; i<this.length; i++){
Math.round(Math.random()) > 0 ? toReturn.push(this*) : toReturn.unshift(this*);
}
return toReturn;
}

/Alpha fade prototype/
MovieClip.prototype.fadeTo = function(value, speed) {
this.onEnterFrame = function() {
this.aV = Math.floor(value-this._alpha);
this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
}
}
/define a function to pick the next item from the array & return it,
filling the side array back up with a different order when it gets emptied.
/
function getNext(){
side.length > 0 ? null : side = main.skuffle();
var toReturn = side.shift();
return toReturn;
}
/define an interval function/
function nextImage(delay){
trace(“nextimage”);
//nowVisible._visible = false;
//nowVisible = getNext();
//nowVisible._visible = true;

nowVisible.fadeTo(0,2);
nowVisible = getNext();
nowVisible.fadeTo(100,10);

}
//start it up.
nextInterval = setInterval(nextImage, 20000);

images.XML file contents:

<?xml version=“1.0” encoding=“utf-8” standalone=“yes”?>
<images>
<pic>
<image>http://new.stralia.com.au/bourgies/images/banners/banner_flashimages.jpg</image>
</pic>
<pic>
<image>http://new.stralia.com.au/bourgies/images/banners/banner_(1)flashimages2.jpg</image>
</pic>
<pic>
<image>http://new.stralia.com.au/bourgies/images/banners/banner_flashimages3.jpg</image>
</pic>
<pic>
<image>http://new.stralia.com.au/bourgies/images/banners/banner_flashimages4.png.jpg</image>
</pic>
</images>

Non-working version: http://new.stralia.com.au/bourgies/flash/flash2.html

Actionscript from 2:
Using the following flashvars data in the HTML page:
<param name=“flashvars” value=“totalimages=4&image1=http://new.stralia.com.au/bourgies/flash/banner_flashimages.jpg&image2=http://new.stralia.com.au/bourgies/flash/banner_flashimages2.jpg&image3=http://new.stralia.com.au/bourgies/flash/banner_flashimages3.jpg&image4=http://new.stralia.com.au/bourgies/flash/banner_flashimages4.jpg” />
---------------------------------------------------var total = int(totalimages);
this.totalImages.text = total;
image = [];
for (i=1; i<=total; i++) {
image* = eval(“image”+i);
eval(“p”+i).loadMovie(image*);
}
main = [p1, p2, p3, p4];
side = [];
//define space to keep track of the last visible item.
nowVisible = {};

//make every mc in the array invisible
for(var i=1; i<main.length; i++){
//main*._visible=false;
main*._alpha=0;
}
//define a shuffle prototype.
Array.prototype.skuffle = function(){
var toReturn = [];
for(var i=0; i<this.length; i++){
Math.round(Math.random()) > 0 ? toReturn.push(this*) : toReturn.unshift(this*);
}
return toReturn;
}
/Alpha fade prototype/
MovieClip.prototype.fadeTo = function(value, speed) {
this.onEnterFrame = function() {
this.aV = Math.floor(value-this._alpha);
this.aV ? this._alpha += this.aV/speed : (this._alpha=value, delete this.onEnterFrame);
}
}
/define a function to pick the next item from the array & return it,
filling the side array back up with a different order when it gets emptied.
/
function getNext(){
side.length > 0 ? null : side = main.skuffle();
var toReturn = side.shift();
return toReturn;
}
/define an interval function/
function nextImage(delay){
trace(“nextimage”);
//nowVisible._visible = false;
//nowVisible = getNext();
//nowVisible._visible = true;
nowVisible.fadeTo(0,10);
nowVisible = getNext();
nowVisible.fadeTo(100,10);
}
//start it up.
nextInterval = setInterval(nextImage, 5000);

Any help would be most appreciated.
Regards,
Nadia