Introduction to XML application in FLASH

Source: Internet
Author: User
Click here to browse the Flash tutorial section about the XML application in FLASH. I have written several articles before. I also collected several articles from the network. However, they are all very simple and commonly used. Here, I will summarize other XML-related descriptions. I hope you can complement each other. Only for the same purpose: to improve together. I. to write standard XML, click here to browse the Flash tutorial section about the application of XML in FLASH. I have written several articles in the past. I also collected several articles from the network. However, they are all very simple and commonly used. Here, I will summarize other XML-related descriptions. I hope you can complement each other. Only for the same purpose: to improve together. I. to write standard XML, click here to browse the Flash tutorial section about the application of XML in FLASH. I have written several articles in the past. I also collected several articles from the network. However, they are all very simple and commonly used. Here, I will summarize other XML-related descriptions. I hope you can complement each other. Only for the same purpose: to improve together.
I. pay attention to the following points when writing standard XML:

  1. List

  2. -Paddingleft-2 ">

  3. A standard XML document must start" "And" "At the end, the first part must declare the XML version, for example, version =" 1.0 ". It should also contain a statement about encoding:" encoding = "UTF-8 ""; XML requires that all tags be closed before the end of the document. if the tag contains content, it must be written as" <标签名> Content "Format, if the content is empty, it should be written inFormat.In this format. Each XML file has a root element, also known as a root node. Nodes have node values and attributes. If the XML node value contains the same characters as the XML tag keyword, XML cannot parse the document. for example, if a node value is greater than or less than a number, the interpreter will generate an error.

2. create a simple instance in FLASH:

// Create a new XML class instance var my_XML: XML = new XML (); // Create a TextArea component to display the XML content var my_TextArea: mx. controls. textArea; // load the external XML file my_XML.load ("my_xml.xml"); // define the onLoad function for the load function --- this is required. XML can be controlled only after loading is successful. Otherwise, no. My_XML.onLoad = function (OK: Boolean) {if (OK) {my_TextArea.text = this;} else {my_TextArea.text = "loading failed... "}}// Ignore blank space: my_XML.ignoreWhite = true;

III. Explanation of FLASH parsing XML. to put it bluntly, it means reading nodes.
First, let's take a look at this picture and get a little bit of an impression.

1. create a new notepad file and enter the following content in it:
 <购买物品>
  <衬衣 颜色="白色" 品牌="雅戈尔">
   
1 piece
  
  <裤子 颜色="深蓝" 品牌="王子裤">
   
2 pieces
  
  <鞋子 颜色="黑色" 品牌="红蜻蜓">
   
3 Double
  
  <总花费金额>
   <打的费>
    
50 RMB
   
   <货物金>
    
$1000
   
  
 Save it as "goods. xml". Note that you must select "Unicode" for encoding ". 2. Next, we will explain the values. How to read the entire XML File: Create a FLA file in the same-level Directory of the XML file, and then place a TextArea component in the scene. And assign the instance name "my_TextArea", and then add the following code in the first frame: var my_XML: XML = new XML (); System. useCodepage = true; var my_TextArea: mx. controls. textArea; my_XML.load ("goods. xml ") my_XML.onLoad = function (OK: Boolean) {if (OK) {my_TextArea.text = this;} else {my_TextArea.text =" loading failed "} Press CTRL ENTER to test the function, you can see the effect. First, let's take a look at how to read the node name or node attribute in XML? For example, how do we read the characters "purchase items" in the example? We use the following statement: this. firstChild. nodeName; if you want to read "shirt": this. firstChild. childNodes [0]. nodeName; if you want to read "1": this. firstChild. childNodes [1]. childNodes [0]. nodeValue; if you want to read the brand of the trousers: this. firstChild. childNodes [1]. attributes. brand; read XML into the LIST component: System. useCodepage = true; var my_TextArea: mx. controls. textArea; var my_List: mx. controls. list; var my_XML: XML = new XML (); my_XML.ignoreWhite = true; my_XML.load ("shopping. xml "); my_XML.onLoad = function (OK: Boolean) {if (OK) {var childnodes = this. firstChild. childNodes; for (I = 0; I
 
  

The above is a detailed description of the XML application in FLASH. For more information, see other related articles in the first PHP community!

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.