我正在尝试通过单个XML文件并使用AS3创建导航和内容系统。
我已经成功导入XML并设置了样式。
我被困在如何创建导航系统上。
示例XML:
?xml version = "1.0" encoding="UTF-8"?>
<XML>
<pages>
<page>
<recordnumber>1</recordnumber/>
<locatn>1. Lorem ipsum dolor sit amet</locatn>
<first>Consectetur adipiscing elit,tortor faucibus ac vestibulum mole</first>
<firstpara>Stie curae tristique et,hac aliquam mattis eu platea pulvinar. Arcu erat id eleifend lacuconsectetur adipiscing elit,tortor faucibus ac vestibulum mole.</firstpara>
<bodytext>hac aliquam mattis eu platea pulvinar. Arcu erat id eleifend lacuconsectetur adipiscing elit,tortor faucibus ac vestibulum mole.
s mollis hac et leo vitae imperdiet habitasse nunc cum semper,elementum ornare eu condimentum vehicula litora consequat feugiat facilisis etiam ridiculus metus vel.
Hendrerit parturient nisl dis enim odio rutrum dignissim,imperdiet dictumst facilisis ac tincidunt luctus at suscipit,tortor montes libero fringilla dui proin.
Egestas tempor blandit condimentum conubia nibh sapien penatibus tincidunt dapibus morbi,sed urna lacinia arcu at senectus duis nostra sollicitudin purus,malesuad
a platea dis mi aenean sodales class sociis rhoncus. Sociis integer commodo dictumst nibh ridiculus nullam dis quam,sapien sem quisque molestie vestibulum semper imperdiet
egestas,tempor porttitor neque eu nam vel morbi. Metus volutpat tortor ad fermentum parturient montes malesuada per lacinia ac a taciti massa,arcu ligula fusce purus pulvinar erat porttitor egestas proin sollicitudin magnis.</bodytext>
</page>
<page>
<recordnumber>2</recordnumber/>
<locatn>1. Lorem ipsum dolor sit amet</locatn>
<first>Consectetur adipiscing elit,arcu ligula fusce purus pulvinar erat porttitor egestas proin sollicitudin magnis.</bodytext>
</page>
<page>
<recordnumber>3</recordnumber/>
<locatn>1. Lorem ipsum dolor sit amet</locatn>
<first>Consectetur adipiscing elit,arcu ligula fusce purus pulvinar erat porttitor egestas proin sollicitudin magnis.</bodytext>
</page>
</pages>
</XML>
布局指南的图片:
到目前为止,我的代码:
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.Font;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Movieclip;
import flash.net.navigateToURL;
import flash.display.SimpleButton
//I Set they' location on stage where the first box will live
var yPlacement: int = 60;
//Set the "x" location on stage where all boxes will line up vertically
var xPlacement: int = 0;
// Set the distance each box should be apart here
var distance: int = 480;
// Initialize the XML,place the xml file name,initialize the URLRequest
// put URLRequest into a new URLLoader,and add event listener on
// myLoader listening for when the XML loading is complete
var myXML: XML = new XML();
var XML_URL: String = "pages3.xml";
var myXMLURL: URLRequest = new URLRequest(XML_URL);
var xmlLoader: URLLoader = new URLLoader(myXMLURL);
xmlLoader.addEventListener("complete",xmlLoaded);
//Create the xmlLoaded function
function xmlLoaded(event: Event): void {
// Place the xml data into the myXML object
myXML = XML(xmlLoader.data);
// Initialize and give var name to the new extemal XMLDocument
var xmlDoc: XMLDocument = new XMLDocument();
// Ignore spacing around nodes
xmlDoc.ignoreWhite = true;
//Define a new name for the loaded XML that is the data in myLoader
var menuXML: XML = XML(xmlLoader.data);
//Parse the XML data into a readable format
xmlDoc.parsexml(menuXML.toXMLString());
// Run the "for each"
// loop to iterate through all of the menu items listed in the external XML file
// This all pertains to the complete box that needs to be scrolled
/* var scrollCompleteholder: Shape = new Shape; */
////scrollCompleteholder.graphics.beginFill(0xF0F0F0);
//scrollCompleteholder.graphics.linestyle(1,0x333333);
//scrollCompleteholder.graphics.drawRect(0,3840,860);
for each(var page: XML in myXML..page) {
// access the value of the "recordnumber" node in our external XML file
var list_recordnumber: String = page.recordnumber.toString();
// access the value of the "locatn" node in our external XML file
var list_locatn: String = page.locatn.toString();
// access the value of the "first" node in our external XML file
var list_first: String = page.first.toString();
// access the value of the "first" node in our external XML file
var list_firstpara: String = page.firstpara.toString();
// access the value of the "first" node in our external XML file
var list_bodytext: String = page.bodytext.toString();
// How many mc's attach to the scrollpane
var num_clips: int = 155;
// y value for next object to be placed
var nextXPos: int = 0;
// counter for()
var n: int = 0;
//Create a movieclip (mc) to hold the attached items
// This all pertains to the style of the Box that holds each person
var rect: Shape = new Shape;
//var color: Number = 0x333333;
rect.graphics.beginFill(0xF0F0F0);
rect.graphics.linestyle(1,0x666666);
rect.graphics.drawRect(0,424,730);
// This all pertains to the text fields that give our boxes their labels,alter values to your liking
var myText1: TextField = new TextField();
myText1.text = list_recordnumber;
myText1.autoSize = TextFieldAutoSize.LEFT;
myText1.x = 4;
myText1.y = 4;
myText1.width = 384;
// get the Textformat of the first character
var TF: TextFormat = myText_01.getTextFormat(0,1)
// set the font color
TF.color = 0xCCCCCC;
// put it on the whole text
myText1.setTextFormat(TF);
addChild(myText1);
//++++++++++++++++++++++++++++++++++++++++++++++
var myText2: TextField = new TextField();
myText2.text = list_locatn;
myText2.autoSize = TextFieldAutoSize.LEFT;
myText2.antiAliasType = AntiAliasType.ADVANCED;
myText2.width = 384;
myText2.wordWrap = true;
myText2.embedFonts = true;
//myText2.scroll = true;
myText2.multiline = true;
myText2.x = 4;
myText2.y = 144;
// get the Textformat of the first character
var TF2: TextFormat = myText_02.getTextFormat(0,1);
// set the font color
TF2.color = 0x000000;
// put it on the whole text
myText2.setTextFormat(TF2);
addChild(myText2);
//++++++++++++++++++++++++++++++++++++++++++++++
var myText3: TextField = new TextField();
myText3.text = list_first;
myText3.autoSize = TextFieldAutoSize.LEFT;
myText3.antiAliasType = AntiAliasType.ADVANCED;
myText3.width = 384;
myText3.wordWrap = true;
myText3.embedFonts = true;
//myText3.scroll = true;
myText3.multiline = true;
myText3.x = 4;
myText3.y = 26;
// get the Textformat of the first character
var TF3: TextFormat = myText_03.getTextFormat(0,1);
// set the font color
TF3.color = 0x339900;
// put it on the whole text
myText3.setTextFormat(TF3);
addChild(myText3);
//++++++++++++++++++++++++++++++++++++++++++++++
var myText4: TextField = new TextField();
myText4.text = list_firstpara;
myText4.autoSize = TextFieldAutoSize.LEFT;
myText4.antiAliasType = AntiAliasType.ADVANCED;
myText4.width = 384;
myText4.wordWrap = true;
myText4.embedFonts = true;
//myText4.scroll = true;
myText4.multiline = true;
myText4.x = 4;
myText4.y = 184;
// get the Textformat of the first character
var TF4: TextFormat = myText_04.getTextFormat(0,1);
// set the font color
TF4.color = 0x999999;
// put it on the whole text
myText4.setTextFormat(TF4);
addChild(myText4);
//++++++++++++++++++++++++++++++++++++++++++++++
var myText5: TextField = new TextField();
//var maxScrollV = 440;
myText5.text = list_bodytext;
/* myText5.autoSize = TextFieldAutoSize.LEFT;*/
myText5.antiAliasType = AntiAliasType.ADVANCED;
myText5.width = 370;
myText5.height = 440;
myText5.wordWrap = true;
myText5.embedFonts = true;
//myText5.scrollV = true;
//myText5.scrollV = myText5.maxScrollV;
myText5.scrollV++;
myText5.multiline = true;
myText5.x = 4;
myText5.y = 280;
// get the Textformat of the first character
var TF5: TextFormat = myText_05.getTextFormat(0,1);
// set the font color
TF5.color = 0x000000;
// put it on the whole text
myText5.setTextFormat(TF5);
addChild(myText5);
//++++++++++++++++++++++++++++++++++++++++++++++
var Timeline_mc = new Movieclip();
//Movieclip holder for each box graphic and text labels to organize everything into container
var clip_mc = new Movieclip();
// Add the rectangle graphic
//clip_mc.addChild(rect);
// Add the text fields
for (n = 0; n < num_clips; n++) {
clip_mc.addChild(myText1);
clip_mc.addChild(myText2);
clip_mc.addChild(myText3);
clip_mc.addChild(myText4);
clip_mc.addChild(myText5);
trace(myXML.recordnumber.@number);
//++++++++++++++++++++++++++++++++++++++++++++++
}
// Put the new movieclip on stage now
addChild(clip_mc);
// Now apply it in its offset Y position to the stage
clip_mc.y = yPlacement;
// X position that it will be placed on stage
clip_mc.x = xPlacement;
// Offset each one in the loop to make sure they don't just get put right on top of each other
xPlacement = xPlacement + distance;
addChild(Timeline_mc);
}
}