Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > About loading text and variables into text fields > Loading and displaying text from an XML document | |||
XML data is a popular way to distribute content on the Internet, in part because it is a widely accepted standard for organizing and parsing data. As such, XML is an excellent choice for sending and receiving data from Flash; however, XML is slightly more difficult to learn than using LoadVars and FlashVars to load data and display text.
this.createTextField("my_txt", 10, 10, 10, 320, 100);
my_txt.autoSize = "left";
my_txt.border = true;
my_txt.multiline = true;
my_txt.wordWrap = true;
var reviews_xml:XML = new XML();
reviews_xml.ignoreWhite = true;
reviews_xml.onLoad = function (success:Boolean):Void {
if (success) {
var childItems:Array = reviews_xml.firstChild.childNodes;
for (var i:Number = 0; i < childItems.length; i++) {
my_txt.text += childItems[i].firstChild.firstChild.nodeValue + "\n";
}
} else {
my_txt.text = "Unable to load external file.";
}
}
reviews_xml.load("http://www.helpexamples.com/flash/xml/reviews.xml");
The first block of code in the preceding snippet creates a new text field on the Stage. This text field is used to display various parts of the XML document that is loaded later. The second block of code handles creating an XML object that will be used to load the XML content. Once the date is completely loaded and parsed by Flash, the XML.onLoad() event handler is invoked and displays the contents of the XML packet in the text field.
Flash displays the following output in the text field on the Stage:
Item 1 Item 2 ... Item 8
For information on security, see Understanding Security.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000890.html