Call the XML document in Flash

Source: Internet
Author: User
Some methods and attributes of the XML class and xmlnode class must be used to call XML documents in flash. We don't need to use that much here. List the methods and attributes used:

XML class:
XML. ignorewhite; // process the white space in the XML document. If it is set to true, the white space is ignored. The default value is false.
XML. Load ("XML document address"); // load the specified XML document.
XML. onload = function (success: Boolean) {}; // called when the XML document is successfully loaded.
XML constructor.

Xmlnode class:
Xmlnode. attributes; // used to specify the attributes of an XML document.
Xmlnode. childnodes; // returns the child-level array of the specified XML Document Object.
Xmlnode. firstchild; // reference the first child in the Child list of the parent node.
Xmlnode. nodevalue; // return the node value of the XML object.
Xmlnode. nodename; // node name of the XML Object

Start the experiment:
First Note: Add encoding = "gb2312" to the XML declaration and use gb2312 encoding. If Chinese characters exist in flash, they must be loaded.CodeAdd system. usecodepage = true before. Use System encoding to prevent garbled characters.

Lab 1:
A simple experiment outputs the nodes in the XML file in flash. Create an XML document and enter the following code in notepad. Save as xml-001.xml.

<? XML version = "1.0"?>
<! -- Xml-001.xml -->
<Firstnode name = "1">
<Childnode name = "1.1" type = "parmname" text = "parmname"/>
<Childnode name = "1.2" type = "parmname" text = "parmname"/>
<Childnode name = "1.3" type = "parmname" text = "parmname"/>
</Firstnode>

The above is a simple XML document with a structure of three child-level nodes nested in a top-level node.

How can I read it in flash? See the operation: Open flash, create a new flash document, save to the directory of the XML document just now, named xml-001.fla. Enter the following code in the first frame:

// Xml-001.fla.
// Instantiate an XML object.
VaR myxml: xml = New XML ();
// Ignore spaces in the XML document during analysis.
Myxml. ignorewhite = true;
// Load the xml-001.xml documentation.
Myxml. Load ("xml-001.xml ");
// Call the XML. onload event.
Myxml. onload = function (success: Boolean)
{
// If the load is successful, success = true; otherwise, success = false;
If (SUCCESS ){
Trace ("loaded successfully! ");
// Output the node name of the top-level node and the attribute name value of the top-level node.
Trace (myxml. firstchild. nodename + ":" + myxml. firstchild. Attributes. Name );
// Use an array to reference the array of sublevel nodes of top-level nodes.
VaR child_arr: array = myxml. firstchild. childnodes;
// Use the nested for statement to traverse all data in the XML document.
// This For traversal is the sublevel node under the top-level node.
For (VAR I = 0; I <child_arr.length; I ++ ){
// Output the node name of the sublevel node under the top-level node and the value of the attribute name of the sublevel node under the top-level node.
Trace (child_arr [I]. nodename + ":" + child_arr [I]. Attributes. Name );
}
} Else {
Trace ("loading failed! ");
}
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.