dcs
08-29-2008, 06:52 AM
Hi.. im having a lil problem in actionScript of flash.
this is the xml code
<xml>
<images>
<image title="1">img/slide/01.jpg</image>
<image title="2">img/slide/02.jpg</image>
<image title="3">img/slide/03.jpg</image>
<image title="4">img/slide/04.jpg</image>
</images>
</xml>
Flash ActionScript
currentframe = mc._currentframe;
xmlImages = new XML();
xmlImages.ignoreWhite = true;
xmlImages.onLoad = loadImages;
xmlImages.load("images.xml");
function loadImages(loaded) {
if (loaded) {
xmlFirstChild = this.firstChild;
imageFileName = [];
totalImages = xmlFirstChild.childNodes[0].childNodes.length;
for (i=0; i<totalImages; i++) {
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].firstChild.nodeValue;
}
randomImage();
}
}
function randomImage() {
if (loaded == filesize) {
var ran = Math.round(Math.random() * (totalImages - 1));
picture_mc.loadMovie(imageFileName[ran], 1);
pause();
}
}
function pause() {
if (currentframe == 1) {
randomImage();
}
}
I dont know why this dsnt work.
if i change the xml file as follows
<xml>
<images>
<image title="img/slide/01.jpg">img/slide/01.jpg</image>
<image title="img/slide/02.jpg">img/slide/02.jpg</image>
<image title="img/slide/03.jpg">img/slide/03.jpg</image>
<image title="img/slide/04.jpg">img/slide/04.jpg</image>
</images>
</xml>
and action script:
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].firstChild.nodeValue;
to
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
it works.
pls help
this is the xml code
<xml>
<images>
<image title="1">img/slide/01.jpg</image>
<image title="2">img/slide/02.jpg</image>
<image title="3">img/slide/03.jpg</image>
<image title="4">img/slide/04.jpg</image>
</images>
</xml>
Flash ActionScript
currentframe = mc._currentframe;
xmlImages = new XML();
xmlImages.ignoreWhite = true;
xmlImages.onLoad = loadImages;
xmlImages.load("images.xml");
function loadImages(loaded) {
if (loaded) {
xmlFirstChild = this.firstChild;
imageFileName = [];
totalImages = xmlFirstChild.childNodes[0].childNodes.length;
for (i=0; i<totalImages; i++) {
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].firstChild.nodeValue;
}
randomImage();
}
}
function randomImage() {
if (loaded == filesize) {
var ran = Math.round(Math.random() * (totalImages - 1));
picture_mc.loadMovie(imageFileName[ran], 1);
pause();
}
}
function pause() {
if (currentframe == 1) {
randomImage();
}
}
I dont know why this dsnt work.
if i change the xml file as follows
<xml>
<images>
<image title="img/slide/01.jpg">img/slide/01.jpg</image>
<image title="img/slide/02.jpg">img/slide/02.jpg</image>
<image title="img/slide/03.jpg">img/slide/03.jpg</image>
<image title="img/slide/04.jpg">img/slide/04.jpg</image>
</images>
</xml>
and action script:
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].firstChild.nodeValue;
to
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
it works.
pls help