As parsing XML to Flash

Source: Internet
Author: User

This is my company a beginner as colleague writes, also takes it out, he uses is the X,y localization method, first looks the XML file the pattern

<item>
<title>321 also fashion </title>
<link>/show.php?id=7</link>
pic/web_08.gif</imgurl>
<date>2008-03-26</date>
</item>

is the title, the connection address, the image address, the date, and then we'll see how the as is parsing the XML file.


PICW = 20
Pich = 80
Link1 = "link"
var main:movieclip = this;
var myxml = new XML ()
Myxml.ignorewhite = True
Myxml.load ("Piclist.xml")
Myxml.onload = function (success) {
if (success) {
_root.createemptymovieclip (loadpic,-1000)
_root[loadpic]._y =20

LOADPP ()
} else {
Trace ("Failed to load")
}
}
function LOADPP () {
MyList = MyXML.firstChild.childNodes
Mylistlen = Mylist.length;
for (i =1; i<=mylistlen;i++) {
var new_mc = _root[loadpic].createemptymovieclip ("NEW_MC" + I, i+100);
new_mc._x = 20;
New_mc._y = ((i-1));
New_mc.createtextfield ("main", 0,100,0,500,20);
New_mc.createtextfield ("Rere", -1,100,20,500,20);
New_mc.createtextfield ("Lianjie", -2,100,40,500,20);
New_mc.main.html = true;
New_mc.main.wordWrap = true;
New_mc.main.text = String (myxml.firstchild.childnodes[i-1].childnodes[0].childnodes);
New_mc.rere.text = String (myxml.firstchild.childnodes[i-1].childnodes[3].childnodes);
New_mc.lianjie.text = Link1;
_root[loadpic].createemptymovieclip ("Pic" +i,i+1)
_root[loadpic]["pic" +i]._x = PICW
_root[loadpic]["pic" +i]._y = (i-1) * Pich
_root[loadpic]["Pic" +i].loadmovie (myxml.firstchild.childnodes[i-1].childnodes[2].childnodes)
Set Text style
btntf = new TextFormat ();
Btntf.color = 0x000000;
Btntf.font = "Verdana"; Font model
Btntf.size = 12; Font size
Btntf.bold = true;
New_mc.lianjie.setTextFormat (btntf);
Button behavior
NEW_MC.I = i-1;
New_mc.onrelease = function () {
var who:number = this.i;
var link:string = Myxml.firstchild.childnodes[who].childnodes[1].childnodes
Trace (link);
GetURL (link, "_blank");
};
New_mc.onrollover = function () {
Who=this.i
This._y = Newy + (MHJ * who);
Menutf = new TextFormat ();
Menutf.color = 0xff9900;
This.lianjie.setTextFormat (MENUTF);
};
New_mc.onrollout = function () {
Menutf = new TextFormat ();
Menutf.color = 0x0000;
This.lianjie.setTextFormat (MENUTF);
}

}
}


Although there are some not standardized writing, but there are many places worth learning.

Original article: Reprint please specify www.111cn.net

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.