akiffen
%Europe/Berlin %434 %2009, 10:26
Hoi,
Ik heb een probleem met XML nodes tellen in AS 2.0
Ik wil graag de hoeveelheid <image> tellen in <images>. De ene keer zijn dit er namelijk 3 en vervolgens kunnen het er 5 zijn.
Deze moet vervolgens in de var aantalImages komen te staan, zodat ik die later kan uitlezen hoeveel images er zijn. Iemand een idee?
Het tellen van de eerste childnodes lukt wel, maar vervolgens kom ik niet verder.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<presentatie>
<specifications>
<scrollspeed>3</scrollspeed>
<pause_seconds>5</pause_seconds>
</specifications>
<media>
<video>
<file>video1.flv</file>
<images>
<image>afb1.jpg</image>
<image>afb3.jpg</image>
<image>afb4.jpg</image>
</images>
<seconden>
<punt>4</punt>
<punt>5</punt>
<punt>6</punt>
</seconden>
<title>Video 1</title>
<description>Beschrijving van de video</description>
<tab>Journaal</tab>
</video>
<video>
<file>video1.flv</file>
<images>
<image>afb1.jpg</image>
<image>afb2.jpg</image>
<image>afb3.jpg</image>
<image>afb4.jpg</image>
<image>afb5.jpg</image>
</images>
<seconden>
<punt>4</punt>
<punt>5</punt>
<punt>6</punt>
<punt>7</punt>
<punt>7</punt>
</seconden>
<title>Video 2</title>
<description>Beschrijving van de video</description>
<tab>Journaal</tab>
</video>
</media>
</presentatie>
Dit is de AS code:
function loadXML(loaded) {
if (loaded) {
trace("loaded");
xmlSpecsNode = this.firstChild.firstChild;
//trace(xmlSpecsNode);
xmlNode = this.firstChild.firstChild.nextSibling;
image = [];
seconds = [];
tag = [];
videofile = [];
mediatitle = [];
description = [];
aantalImages = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
//aantalImages[i] = xmlNode.firstChild.firstChild.nextSibling.childNod es.length;
aantalImages[i] = xmlNode.childNodes[i].childNodes[1].firstChild.firstChild.nodeValue;
videofile[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
mediatitle[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
tag[i] = xmlNode.childNodes[i].childNodes[5].firstChild.nodeValue;
}
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
trace(aantalImages);
scrollSpeed = xmlSpecsNode.childNodes[0].firstChild.nodeValue;
pauseTime = xmlSpecsNode.childNodes[1].firstChild.nodeValue;
pauseSeconds = pauseTime * 1000;
//firstImage();
} else {
content = "file not loaded!";
}
}
if(!image)
{
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("presentatie_onlinegroei.xml");
}
else
{
//nextImage();
}
Gebruik [as] tags voor AS code.
Ik heb een probleem met XML nodes tellen in AS 2.0
Ik wil graag de hoeveelheid <image> tellen in <images>. De ene keer zijn dit er namelijk 3 en vervolgens kunnen het er 5 zijn.
Deze moet vervolgens in de var aantalImages komen te staan, zodat ik die later kan uitlezen hoeveel images er zijn. Iemand een idee?
Het tellen van de eerste childnodes lukt wel, maar vervolgens kom ik niet verder.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<presentatie>
<specifications>
<scrollspeed>3</scrollspeed>
<pause_seconds>5</pause_seconds>
</specifications>
<media>
<video>
<file>video1.flv</file>
<images>
<image>afb1.jpg</image>
<image>afb3.jpg</image>
<image>afb4.jpg</image>
</images>
<seconden>
<punt>4</punt>
<punt>5</punt>
<punt>6</punt>
</seconden>
<title>Video 1</title>
<description>Beschrijving van de video</description>
<tab>Journaal</tab>
</video>
<video>
<file>video1.flv</file>
<images>
<image>afb1.jpg</image>
<image>afb2.jpg</image>
<image>afb3.jpg</image>
<image>afb4.jpg</image>
<image>afb5.jpg</image>
</images>
<seconden>
<punt>4</punt>
<punt>5</punt>
<punt>6</punt>
<punt>7</punt>
<punt>7</punt>
</seconden>
<title>Video 2</title>
<description>Beschrijving van de video</description>
<tab>Journaal</tab>
</video>
</media>
</presentatie>
Dit is de AS code:
function loadXML(loaded) {
if (loaded) {
trace("loaded");
xmlSpecsNode = this.firstChild.firstChild;
//trace(xmlSpecsNode);
xmlNode = this.firstChild.firstChild.nextSibling;
image = [];
seconds = [];
tag = [];
videofile = [];
mediatitle = [];
description = [];
aantalImages = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
//aantalImages[i] = xmlNode.firstChild.firstChild.nextSibling.childNod es.length;
aantalImages[i] = xmlNode.childNodes[i].childNodes[1].firstChild.firstChild.nodeValue;
videofile[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
mediatitle[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
tag[i] = xmlNode.childNodes[i].childNodes[5].firstChild.nodeValue;
}
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
trace(aantalImages);
scrollSpeed = xmlSpecsNode.childNodes[0].firstChild.nodeValue;
pauseTime = xmlSpecsNode.childNodes[1].firstChild.nodeValue;
pauseSeconds = pauseTime * 1000;
//firstImage();
} else {
content = "file not loaded!";
}
}
if(!image)
{
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("presentatie_onlinegroei.xml");
}
else
{
//nextImage();
}
Gebruik [as] tags voor AS code.