Complete and concise flash processing XML document data tutorial

Source: Internet
Author: User

Instance 4:
Use the list component to create an MP3 playlist.
Create an XML document and enter Code , And then save as xml-004.xml.

Copy code The Code is as follows: <? XML version = "1.0" encoding = "gb2312"?>
<Mp3list>
<MP3 Path = "jmzcg133"> asan-Singing In loneliness </MP3>
<MP3 Path = "jmjywsls.mp3"> lonely because of who you miss </MP3>
<MP3 Path = "szwspdxd.mp3"> old wolf-brother sleeping in my upper bunk </MP3>
<MP3 Path = ".mp3"> vow-Buddha seeking </MP3>
<MP3 Path = "xyzth.pdf"> next day </MP3>
<MP3 Path = "nswdxfm.pdf"> Yi nengjing-Are you happy? </MP3>
<MP3 Path = "aqfx133"> love revival (rongzuer) </MP3>
<MP3 Path = "qrlg.mp3"> fengmu Xinnian-Autumn and Japanese love songs </MP3>
<MP3 Path = "qnyh.mp3"> Leslie Cheung-ghost </MP3>
<MP3 Path = "a.mp3"> A great English song (often played in bars) </MP3>
</Mp3list>

XML structure:
<Mp3list> top-level nodes in the XML document.
<MP3 Path = "jmzcg133"> asan-Sub-nodes under the top-level node of lonely singing </MP3>. path is the attribute under the MP3 node, "asan lonely singing" is the value of MP3 nodes.

Open flash to create a new flash document, the size of 200*150, save to the directory of the XML document just now, named as xml-04.fla. Create two layers named actions and cont respectively. In the cont layer, pull a list component to the first frame. The size is 200*150, the Instance name is mp3_list, and enter the following code in the first frame of the actions layer:

Copy code The Code is as follows: // xml-004.fla.
// Use the system code to prevent garbled characters.
System. usecodepage = true;
// Instantiate an XML object.
VaR myxml: xml = New XML ();
// Ignore spaces in the XML document during analysis.
Myxml. ignorewhite = true;
// Load the xml-004.xml documentation.
Myxml. Load ("xml-004.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! ");
// Use an array to reference the array of sublevel nodes of top-level nodes.
VaR child_arr: array = myxml. firstchild. childnodes;
// This For traversal is the sublevel node under the top-level node.
For (VAR I = 0; I <child_arr.length; I ++ ){
// Add the song to the list component.
// Child_arr [I]. firstchild. nodevalue: the node value of the XML node.
// Child_arr [I]. Attributes. path is the path attribute of the XML node.
Mp3_list.additem ({label :( I + 1) + "." + child_arr [I]. firstchild. nodevalue, data: child_arr [I]. Attributes. Path });
}
} Else {
Trace ("loading failed! ");
}
};
// The listevent function executes the change event in the list component.
Function listevent (): void
{
// This is the song address. You can use the loadsound method of the sound class to play the song. For example, mysound. loadsound (mp3_list.selecteditem.data). For details, see the help documentation.
Trace (mp3_list.selecteditem.data );
}
// Add a frame listener.
Mp3_list.addeventlistener ("change", listevent );

Package File Download

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.