Complete simple Flash process XML document data tutorial next _flash as

Source: Internet
Author: User
Example 4:
Use the list component to make a MP3 playlist.
Create a new XML document, enter the following code in Notepad, and save it as Xml-004.xml.

Copy Code code as follows:

<?xml version= "1.0" encoding= "gb2312"?>
<mp3List>
<mp3 path= "Jmzcg.mp3" > Asan-Loneliness in singing </mp3>
<mp3 path= "Jmjywsls.mp3" > Loneliness is because of missing who </mp3>
<mp3 path= "Szwspdxd.mp3" > Old Wolf-sleeping on my upper bunk brother </mp3>
<mp3 path= "Qf.mp3" > Oath-Seek Buddha </mp3>
<mp3 path= "Xyzth.mp3" > Next Stop Days </mp3>
<mp3 path= "Nswdxfm.mp3" > Yi Jing-you are my happiness </mp3>
<mp3 path= "Aqfx.mp3" > Love Renaissance (Joey) </mp3>
<mp3 path= "Qrlg.mp3" > Mu-Autumn Sonata </mp3>
<mp3 path= "Qnyh.mp3" > Leslie Cheung-Qian Female Ghosts </mp3>
<mp3 path= "A.mp3" > A great English song (often put in bars) </mp3>
</mp3List>

XML Structure:
<mp3list>xml the top-level node in the document.
<mp3 path= "Jmzcg.mp3" > Asan-Loneliness in singing </mp3> child nodes under the top-level node, path is the attribute under the MP3 node, "Asan-loneliness in singing" is the MP3 node value.

Open Flash Create a new flash document, size 200*150, saved to the directory of the XML document just now, named Xml-04.fla. New 2 layers Name the actions, Cont, and the Cont layer to pull a list component to the first frame. The size is 200*150, the instance name is the first frame of the mp3_list,actions layer, enter the following code:

Copy Code code as follows:

Xml-004.fla.
Use system encoding. Prevent garbled characters.
System.usecodepage = true;
Instantiates an XML object.
var myxml:xml = new XML ();
Whitespace in an XML document is ignored during profiling.
Myxml.ignorewhite = true;
Loads the Xml-004.xml document.
Myxml.load ("Xml-004.xml");
Invokes the Xml.onload event.
Myxml.onload = function (Success:boolean)
{
If the load succeeds, success=true; otherwise success=false;
if (success) {
Trace ("Load succeeded!");
Use an array to refer to an array of neutron-level nodes of the top-level node.
var child_arr:array = myxml.firstChild.childNodes;
This for traversal is a child 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 This is the node value of the XML node.
Child_arr[i].attributes.path This is the path attribute under the XML node.
Mp3_list.additem ({label: (i+1) + "." +child_arr[i].firstchild.nodevalue, Data:child_arr[i].attributes.path});
}
} else {
Trace ("Load failed!");
}
};
The Listevent function is to perform the Change event in the list component
function Listevent (): Void
{
This is the song address. Use the Loadsound method of sound class to play the song. Example: Mysound.loadsound (mp3_list.selectedItem.data); see the help documentation for details.
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.