PDA

View Full Version : Random Image Loading via XML



tranism
April 25th, 2005, 05:40 PM
i'm trying to randomly load images via xml but my output window keeps saying "undefined".

can somebody help me please?


function loadXML(loaded){
if(loaded){
xmlNODE = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total;i++){
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
randomImage();
}else{
content = "file not loaded!";
}
}
xmlData =new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("bg.xml");

p = 0;
function randomImage(){
if(loaded == filesize){
p = Math.floor(Math.random() * total);
bgholder._alpha = 0;
bgholder.loadMovie(image[0], 1);
}
}

foodpk
April 25th, 2005, 06:24 PM
You'll have to post your XML file too.

tranism
April 25th, 2005, 06:32 PM
You'll have to post your XML file too.

here it is
.
.
.
.
I also need the images to load in randomly. Doesn't need to slideshow or anything. Just randomly choose an image in the XML que. I'm using the Math.random function but not sure how to implement it.

tranism
April 25th, 2005, 08:30 PM
okay, i got the image loading but I need help making it load a random image and fading it in.

here's the current code

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("bg.xml");

p = 0;
function firstImage() {
trace("blahblahblah firstImage")
if (loaded == filesize) {
bgholder._alpha = 0;
if (bgholder._alpha<100) {
bgholder._alpha += 10;
bgholder.loadMovie(image[0], 1);
}
}
}

scotty
April 26th, 2005, 04:24 AM
function randomImage() {
p = Math.floor(Math.random()*image.length);
bgholder.loadMovie(image[p]);
}

scotty(-:

tranism
April 26th, 2005, 01:27 PM
function randomImage() {
p = Math.floor(Math.random()*image.length);
bgholder.loadMovie(image[p]);
}

scotty(-:

where do i place it? it's not working. and my fade in code isn't working either. :(

tranism
April 26th, 2005, 02:02 PM
ok so i modified my code. the fade in is working and the random load is working. here's the latest code. this is placed in the actions layer.



p = 0;
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("bg.xml");

function firstImage() {
p = Math.floor(Math.random()*image.length);
if (loaded == filesize) {
_parent.fileLoaded = 1;
bgholder.loadMovie(image[p]);
}
}


then this code is placed on the actual empty movieclip called 'bgholder'.



onClipEvent (load) {
this._alpha = 0;
}
onClipEvent (enterFrame) {
if (_root.fileLoaded) {
this._alpha += 10;
}
}


everything works except every now and then, it fails to load the random image and I get an "undefined" error in my output window. 80% of the time it works fine. any ideas why this is happening?

here's the latest xml file.

scotty
April 26th, 2005, 02:32 PM
Where are loaded and filesize defined?

scotty(-:

tranism
April 26th, 2005, 02:48 PM
**** you're right. I didn't define them.



filesize = bgholder.getBytesTotal();
loaded = bgholder.getBytesLoaded();


so where do I place this?