AS2.0 support for XML is not built-in (build-in), nor is it based on the ECMAScript for XML (E4X) standard. While AS3.0 support for XML conforms to the E4X standard, its design has three advantages:
1. Easy. Includes operation and readability. You will find that the operation of XML in AS3.0 is as straightforward as an ordinary object object. The statement is very plain and smooth.
2. Continuity. The design of its various functions is consistent with the rest of the AS3.0 and is easy to understand.
3. Familiar with. Operators and operational logic are quite familiar to us.
In the AS2.0 era, in order to solve this part of the problem
Efficiency.
Efficiency includes two aspects, development efficiency, and code execution efficiency. Discussion on the efficiency of development. AS3.0 is far more efficient for XML execution than AS2.0 without built-in XML support.
Input of XML
In the AS2.0 era, entering XML code in lines of code is a pain. If it's not read from a file, we're going to put up with a long string of strings that squeeze together.
And in the AS3.0, it's too easy. Directly in accordance with the content of XML to lose, want to change lines on line, want to tab on the tab, just a word, cool.
Create a new FLA, select the first frame, F9 Open the Action panel and enter the following code:
http://www.kingda.org
Example 1
var kingdaxml:xml =
<tutorial>
<item id= ' 1 ' >
<level>2</level>
<title> a Flash 9</title>
</item>
<item id= ' 2 ' >
<level>3</level>
<title> Binding classes</title>
</item>
<item id= ' 3 ' >
<level>4</level>
<title>document class</title>
</item>
</tutorial>
Trace (Kingdaxml.item[1].level); Output:3
Example 2
var ks:string = "<root><txt>this is a test</txt></root>";
var kxml:xml = new XML (KS);
Trace (KXML.txt); Output:this is a test;
Example 1 Note that no, directly write XML content in the back, want to change lines on the line, want to tab on the tab, how cool. When you don't want to write a string in AS2.0, you can't change a line.
By the end of this sentence, we have written a string-like form that is immediately understood by Flash as an XML object, so we can immediately use the word "." operator to access the corresponding property. In this case, the level value of the 2nd item node is accessed.
Is it better to have such a simple and intuitive way of visiting than the AS2.0 childnodes?
But be aware that you can finally add ";" End. But I didn't add to the visual beauty of XML. This does not matter, compile-time will not consider this point.
In fact, as long as you like, AS1.0, 2.0, 3.0 in the end of the statement can not add ";" Resolution But this is not a good programming habit, more inconsistent with the strict requirements of the self grammar. So I suggest that, in addition to XML can not add, the rest should be added, hehe.
Example 2 shows how to convert a string that contains XML content into an XML object. is converted using the constructor of the XML.
AS3 more interesting is that you can use existing variables to directly construct XML, resulting in convenient programming features. The following example.
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.