好的,我要做的是创建一个多维数组,它将根据单击哪个按钮从xml文件中提取文本,swfs和/或图像。
我不明白的是如何像文本一样从文件中提取swf或图像文件。说实话,我完全迷路了,真的需要一些帮助来解决这个问题。我需要拉文本和图像或swf文件从xml取决于哪个按钮被点击,我试图把这个放在一起,但我给了自己一个头痛试图了解我在哪里出错。
var pageXML:XML;
//Load the XML file.
var pageXMLLoader = new URLLoader();
pageXMLLoader.load(new URLRequest("scripts/xml/content.xml"));
pageXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlIOErrorHandler);
pageXMLLoader.addEventListener(Event.COMPLETE, pageXMLLoaded);
// Intro page variables for title
var swfContainer:Sprite = new Sprite();
var imgContainer:Sprite = new Sprite();
var imgLoader:Loader = new Loader();
var swfLoader:Loader = new Loader();
//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(e.target.data);
imgLoader.load(new URLRequest(pageXML.pages.page.image));
swfLoader.load(new URLRequest(pageXML.pages.page.swfURL));
trace(pageXML.pages.page.image);
trace(pageXML.pages.page.swfURL);
}
// Choose page transition function
function choosePageTransition(e:MouseEvent):void {
var pageNumber:uint;
mcContent.y = 30; // Why do I need to reset the y position each time?
// 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(contentRBottomTxt);
pageContent.addChild(contentRTopTxt);
pageContent.addChild(contentTxt);
pageContent.addChild(headingTxt);
break;
case "navBtn1" :
trace(e.currentTarget.name);
pageNumber = 2;
mcContent.removeChildAt(0);
mcContent.addChildAt(pageContent,0);
pageContent.addChild(contentRBottomTxt);
pageContent.addChild(contentRTopTxt);
pageContent.addChild(contentTxt);
pageContent.addChild(headingTxt);
break;
case "navBtn2" :
trace(e.currentTarget.name);
pageNumber = 3;
mcContent.removeChildAt(0);
mcContent.addChildAt(pageContent,0);
pageContent.addChild(contentRBottomTxt);
pageContent.addChild(contentRTopTxt);
pageContent.addChild(contentTxt);
pageContent.addChild(headingTxt);
break;
... 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 >
} // < /If Statement >
} // < /Function >
我的xml文件看起来有点像这样(它很长,所以我将发布部分):
<?xml version="1.0" encoding="utf-8"?>
<site>
<!--<sitetitle><![CDATA[<strong>Transplant the Heart</strong>]]></sitetitle>-->
<pages>
<page pagenumber="1">
<title><![CDATA[<h1>Page #1</h1>]]></title>
<content><![CDATA[<p>Aliquam nec dui neque. Aenean rutrum suscipit turpis vel fringilla. </p>]]></content>
<contenttr><![CDATA[Cras non risus nisi. Nam tincidunt lacinia massa, vel interdum massa ultricies.]]></contenttr>
<contentbr><![CDATA[Aliquam erat volutpat. Etiam eget mauris ante, sit amet placerat tortor.]]></contentbr>
<image>imgs/png/titleLarge.png</image>
<swfURL>transplantSpecialists.swf</swfURL>
</page>
</pages>
</site>
你确定你的结构是正确的吗?像这样…
project folder
| main.swf
| scripts/
| xml/
| content.xml
| imgs/
| png/
| titleLarge.png
| transplantSpecialists.swf