I’m a little stuck and could really use some help. I posted a question on here previously, but I figured out what the issue was there… sort of. Not completely, but enough to know I may be in over my head trying to adjust it.
So now I’m asking if anyone has heart enough to tell me how I would take this code and fix it so that I can include swf and image files only when I need them. They won’t always be in every node:
var pageXMLLoader = new URLLoader();
pageXMLLoader.load(new URLRequest("scripts/xml/content.xml"));
pageXMLLoader.addEventListener(Event.COMPLETE, pageXMLLoaded);
//This function is called when the XML file is loaded
function pageXMLLoaded(e:Event):void {
//Create a new XML object from the loaded XML data
//pageXML = new XML(pageXMLLoader.data);
pageXML = new XML(e.target.data);
}
// Set page number variable
var pageNumber:uint;
mcContent.y = 30;
// Set up if for mouse click
if (e.type == MouseEvent.CLICK) {
// Switch based on target name
switch (e.currentTarget.name) {
case "navBtn0" :
trace(e.currentTarget.name);
pageNumber = 1;
mcContent.removeChildAt(0);
mcContent.addChildAt(pageContent,0);
pageContent.addChild(contentTxt);
pageContent.addChild(headingTxt);
break;
case "navBtn1" :
trace(e.currentTarget.name);
pageNumber = 2;
mcContent.removeChildAt(0);
mcContent.addChildAt(pageContent,0);
pageContent.addChild(contentTxt);
pageContent.addChild(headingTxt);
break;
case "navBtn2" :
... code shortened
}
// Loop through the XML file
for each (var page:XML in pageXML.pages.page) {
// "page.@pagenumber" points to "pagenumber" in the XML file.
if (page.@ pagenumber == pageNumber) {
// Set the title
headingTxt.htmlText = page.title;
// Set the page content
contentTxt.htmlText = page.content;
contentRTopTxt.htmlText = page.contenttr;
contentRBottomTxt.htmlText = page.contentbr;
// Exit the loop
break;
}
} // < /For Loop >
I got lost in your code, but here is a quick example on how you could retrieve the correct page using E4X
(var pageContent : XML = pageXML.pages.page.(@pagenumber == 1)[0];)and also a check if image or SWF exists.Test.as
content.xml