Hi,
I’m trying to create an xml-based slideshow in flash and am having trouble pushing some code into an array.
The following is an extract showing how my xml file is structured:
The urls are stored as attributes within the garment tag and the rest of the caption is stored with separate tags nested within the garment tags:
In my .fla file I have the following code:
With the for loop I'm trying cycle through the ss array, pull out the url attributes as well as the rest of the caption, and assign the values to the arrays called "captions" and "urls".
Since my url was stored as an attribute, the following line of code works to push the url into the urls array:
urls.push("images/" + ss.attributes.url);
...however, the captions line entered as follows doesn’t push the captions into the captions array:
captions.push(ss.childNodes[0].firstChild.nodeValue);
It only outputs the information contained in the <title> tag, ie. Classic Design Formal Suit
Since the caption isn't stored as an attribute, I assume I need the following code to be pushed into the captions array, but I don’t know how to do it.
Can someone tell me how I can fix the code?
Appreciate any help offered.
I’m trying to create an xml-based slideshow in flash and am having trouble pushing some code into an array.
The following is an extract showing how my xml file is structured:
Code:
<slideshow>
<garment url="formal01.jpg">
<title>Classic Design Formal Suit</title>
<style>5993</style>
<description>Olorperat illaor sim dio od dolore velit atie modiatem adio et ipit praesectem erit, vel ipsuscip er sit velit ipisciduis nulla.</description>
<price>$???</price>
<colours>Black</colours>
<sizes>87cm to 152cm</sizes>
</garment>
<garment url="formal02.jpg">
<title>Another title goes here</title>
<style>5994</style>
<description>Olorperat illaor sim dio od dolore velit atie modiatem adio et ipit praesectem erit, vel ipsuscip er sit velit ipisciduis nulla.</description>
<price>$???</price>
<colours>Black, White</colours>
<sizes>87cm to 137cm</sizes>
</garment>
</slideshow>
The urls are stored as attributes within the garment tag and the rest of the caption is stored with separate tags nested within the garment tags:
In my .fla file I have the following code:
Code:
var ssx:XML = new XML();
ssx.ignoreWhite = true;
var currentIndex:Number = 0;
var captions:Array = new Array();
var urls:Array = new Array();
ssx.onLoad = function(success) {
if (success) {
var ss:Array = ssx.firstChild.childNodes; //stores pictures as separate elements
for (i=0;i<ss.length;i++) {
urls.push("images/" + ss[i].attributes.url);
captions.push(ss[i].childNodes[0].firstChild.nodeValue);
}
frame_mc.images_mc.loadMovie(urls[currentIndex]);
captions_txt.htmlText = captions[currentIndex];
}
else
{
trace("XML file failed to load.");
}
}
ssx.load("formalwear.xml");
With the for loop I'm trying cycle through the ss array, pull out the url attributes as well as the rest of the caption, and assign the values to the arrays called "captions" and "urls".
Since my url was stored as an attribute, the following line of code works to push the url into the urls array:
urls.push("images/" + ss.attributes.url);
...however, the captions line entered as follows doesn’t push the captions into the captions array:
captions.push(ss.childNodes[0].firstChild.nodeValue);
It only outputs the information contained in the <title> tag, ie. Classic Design Formal Suit
Since the caption isn't stored as an attribute, I assume I need the following code to be pushed into the captions array, but I don’t know how to do it.
Code:
var caption:String = ""
caption += "<b>"
caption += ss[0].childNodes[0].firstChild.nodeValue;
caption += "\n\n</b>";
caption += "<b>Style Number</b>\n"
caption += ss[0].childNodes[1].firstChild.nodeValue;
caption += "\n\n";
caption += "<b>Description</b>\n"
caption += ss[0].childNodes[2].firstChild.nodeValue;
caption += "\n\n";
caption += "<b>Price</b>\n"
caption += ss[0].childNodes[3].firstChild.nodeValue;
caption += "\n\n";
caption += "<b>Colours</b>\n"
caption += ss[0].childNodes[4].firstChild.nodeValue;
caption += "\n\n";
caption += "<b>Sizes</b>\n"
caption += ss[0].childNodes[5].firstChild.nodeValue;
Can someone tell me how I can fix the code?
Appreciate any help offered.