-
AS not recognizing next sibling?
Hey all;
I've got an external xml file with several child nodes being read into my movie. Here is the xml:
PHP Code:
<catalog>
<albums>
<imageNode jpegURL="alb01_img01.jpg">Description of Album 1</imageNode>
<imageNode jpegURL="alb02_img01.jpg">Description of Album 2</imageNode>
</albums>
<videos>
<imageNode jpegURL="vid01_img01.jpg">Description of Video 1</imageNode>
<imageNode jpegURL="vid02_img01.jpg">Description of Video 2</imageNode>
</videos>
</catalog>
I have my AS set up to loop thru the nodes and load the given info (jpg or text) into the appropriate spots. Each child node (albums, videos) is loaded into its own MC when called. I was able to get the first child (albums) to display correctly and to list all the albums listed. Once I had that working I made a duplicate of that MC(albumsMC) and changed the name to videosMC. My thinking was that all I would need to change was the reference to the correct child node and all should work correctly.
But heres where it all goes wrong. I know I am referencing the correct child node because videosMC loads the first child jpg & text (vid01_img01)...But the problem is that the rest of the nodes in the <videos> parent are not displayed. So I'm really confused as to why this is happening. Nothing else has changed about the AS except for referencing the next sibling. Here is the AS:
code: function buildList() {
theDepth = 100;
this.createEmptyMovieClip ("con", 10);
nodeCount=albumXML.firstChild.firstChild.nextSibli ng.childNodes.length;
for (u = 0; u < nodeCount; u++) {
//Build the content listing
buildContent();
} //Attaches the clip of items, to the Macromedia scrollpane component,
// which has an instance name of "albumPane".
this.albumPane.setScrollContent (con);
}
function buildContent(){
theJpg = albumXML.firstChild.firstChild.nextSibling.childNo des[u].attributes.jpegURL;
theInfo = albumXML.firstChild.firstChild.nextSibling.childNo des[u].childNodes;
theName = "item_" + u;
con.attachMovie("contentMC", theName, theDepth++, {_y :350 * spacing});
con[theName].imgHolder.loadMovie(theJpg);
con[theName].infoText.html = true;
con[theName].infoText.htmlText = theInfo;
spacing++;
}
stop();
Please help, I'm at wits end. Thanks to all in advance.
-
Hi jedifunk,
From what I can see, it's a scoping issue. You have defined the variable u inside buildList and then use the same variable inside buildContent. This could be the source of your issue. Your other variables have dubious scope also, such as con, spacing.
I would recommend something more like the following:
code:
function buildList()
{
theDepth = 100;
this.createEmptyMovieClip ("con", 10);
var videoNodeList = albumXML.firstChild.childNodes[1].childNodes;
for( var i=0; i < videoNodeList.length; i++ )
{
buildContent( videoNodeList, i );
}
//Attaches the clip of items, to the Macromedia scrollpane component,
// which has an instance name of "albumPane".
this.albumPane.setScrollContent (con);
}
function buildContent( xmlNodeList, intIndex )
{
var theJpg = xmlNodeList[intIndex].attributes.jpegURL;
var theInfo = xmlNodeList[intIndex].childNodes;
var theName = "item_" + intIndex;
con.attachMovie("contentMC", theName, theDepth++, {_y :350 * spacing});
con[theName].imgHolder.loadMovie(theJpg);
con[theName].infoText.html = true;
con[theName].infoText.htmlText = theInfo;
spacing++;
}
stop();
Hope this helps!
Tim Walters
Senior Developer
XML Evangelist
"XML isn't a language, it's a way of life!"
-
Thanks for the reply! I had already found my problem (had an unformated <br> in my text). But I've implemented your code, as I think this will work better and keep the scope of things a little less messy.
Now I'm working on adding a second jpg for each node, and also making the textfields size themselves dynamically according to the length of text in each node. Any thoughts on the best way to do either of those?
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|