AS2.0's support for XML is not built-in, nor is it based on the ECMAScript for XML (E4X) standard. The support for XML in AS3.0 complies with the E4X standard, and its design has three advantages:
1. Simple. Includes operation and readability. You will find that the operation of XML in AS3.0 is as easy to understand as an ordinary Object object. The sentences are very simple and smooth.
2. Continuity. The design of its various functions is consistent with the rest of AS3.0 and is easy to understand.
3. Familiarity. Operators and operation logic are both quite familiar and easy to use.
In the AS2.0 era, in order to solve this problem
efficiency.
Efficiency includes two aspects: development efficiency, and code execution efficiency. The discussion on development efficiency is shown above. AS3.0 is far more efficient in XML execution than AS2.0 without built-in XML support.
XML input
In the AS2.0 era, it was a pain to enter XML code into lines of code. If we are not reading from a file, we have to endure a long string of strings squeezed together.
And in AS3.0, it's too simple. Just enter directly according to the content of XML. If you want to change the line, just change the line. If you want to open it, just Tab, just one word, it’s great.
Create a new fla, select the first frame, open the action panel in F9 and enter the following code:
//
//Example 1
var kingdaXML:XML =
<tutorial>
<item id='1'>
<level>2</level>
<title> First touch of 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 ([1].level); //output:3
//Example 2
var kS:String = "<root><txt>this is a test</txt></root>";
var kXML:XML = new XML(kS);
trace (); //output:this is a test;
Did you notice it in Example 1? Just write XML content directly at the back. If you want to change the line, just open it, and if you want to tab, tab. It’s so cool. I don’t think that when writing string in AS2.0, it won’t work if I change the line.
After writing this sentence, the form we wrote similar to string was immediately understood by Flash as an XML object, so we can immediately use the "." operator to access the corresponding attributes. In this example, the level value of the second item node is accessed.
Is such a simple and intuitive access method much better than the childNodes that are the same thousand times in AS2.0?
But be careful, you can add ";" to end. But I didn't add it for the visual aesthetics of XML. This doesn't matter, it won't be considered during compilation.
In fact, as long as you like, you can not add the ";" sign when the statement ends in AS1.0, 2.0, and 3.0. But this is not a good programming habit, nor does it meet the rigorous self-grammatical requirements. Therefore, I suggest that except for XML, you can not add everything else, haha.
Example 2 shows how to convert a string containing XML content into an XML object. Use XML constructor to convert.
What's more interesting about AS3 is that existing variables can be used to directly construct XML, bringing convenient programming features. The following example is.
1. Simple. Includes operation and readability. You will find that the operation of XML in AS3.0 is as easy to understand as an ordinary Object object. The sentences are very simple and smooth.
2. Continuity. The design of its various functions is consistent with the rest of AS3.0 and is easy to understand.
3. Familiarity. Operators and operation logic are both quite familiar and easy to use.
In the AS2.0 era, in order to solve this problem
efficiency.
Efficiency includes two aspects: development efficiency, and code execution efficiency. The discussion on development efficiency is shown above. AS3.0 is far more efficient in XML execution than AS2.0 without built-in XML support.
XML input
In the AS2.0 era, it was a pain to enter XML code into lines of code. If we are not reading from a file, we have to endure a long string of strings squeezed together.
And in AS3.0, it's too simple. Just enter directly according to the content of XML. If you want to change the line, just change the line. If you want to open it, just Tab, just one word, it’s great.
Create a new fla, select the first frame, open the action panel in F9 and enter the following code:
//
//Example 1
var kingdaXML:XML =
<tutorial>
<item id='1'>
<level>2</level>
<title> First touch of 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 ([1].level); //output:3
//Example 2
var kS:String = "<root><txt>this is a test</txt></root>";
var kXML:XML = new XML(kS);
trace (); //output:this is a test;
Did you notice it in Example 1? Just write XML content directly at the back. If you want to change the line, just open it, and if you want to tab, tab. It’s so cool. I don’t think that when writing string in AS2.0, it won’t work if I change the line.
After writing this sentence, the form we wrote similar to string was immediately understood by Flash as an XML object, so we can immediately use the "." operator to access the corresponding attributes. In this example, the level value of the second item node is accessed.
Is such a simple and intuitive access method much better than the childNodes that are the same thousand times in AS2.0?
But be careful, you can add ";" to end. But I didn't add it for the visual aesthetics of XML. This doesn't matter, it won't be considered during compilation.
In fact, as long as you like, you can not add the ";" sign when the statement ends in AS1.0, 2.0, and 3.0. But this is not a good programming habit, nor does it meet the rigorous self-grammatical requirements. Therefore, I suggest that except for XML, you can not add everything else, haha.
Example 2 shows how to convert a string containing XML content into an XML object. Use XML constructor to convert.
What's more interesting about AS3 is that existing variables can be used to directly construct XML, bringing convenient programming features. The following example is.