As read XML file to Flash

Source: Internet
Author: User

Today to see how flash is the analysis of XML documents, and in the Flash file display, home we look at the XML file:

<?xml version= "1.0" encoding= "UTF-8"?>
<channel>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=5</link>
<date>2008-03-22 00:00:00</date>
</item>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=6</link>
<date>2008-03-22 00:00:00</date>
</item>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=7</link>
<date>2008-03-22 00:00:00</date>
</item>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=8</link>
<date>2008-03-22 00:00:00</date>
</item>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=9</link>
<date>2008-03-22 00:00:00</date>
</item>
<item>
<title>6 field half full No. 08032 period Recommendation: Roman Derby "and" ...</title>
<link>/show.php?id=10</link>
<date>2008-03-22 00:00:00</date>
</item>
</channel>

The above is the XML document I generated with PHP, build method to the site to find, there are tutorials. The most important thing is the as code, because we're talking as if we read the XML file, so that's the most important thing. Look at the as code below, we build a file in Flash.

Building XML objects
var myxml = new XML ();
var main:movieclip = this;

//Load XML file
Myxml.load ("Newslist.xml");
//Ignore spaces
Myxml.ignorewhite = true;//Ignore null Gemer think false
//Process XML Object function
Newy = 20;
Newx = 20;
Mhj = 20;//line spacing
Myxml.onload = function (success) {
 node = this.firstChild.childNodes;
 textnum = Node.length;
 for (i = 0; i < Textnum; i++) {
  var NEW_MC = Main.createemptymovieclip ("NEW_MC" + I, i);
  new_mc._x = Newx;
  new_mc._y = newy + (MHJ * i);
  new_mc.moveto (Newx,newy);
  new_mc.createtextfield ("main", 0,0,0,500,20);
  new_mc.main.html = true;
  new_mc.main.wordwrap = true;
  new_mc.main.text = String (myxml.childnodes[0].childnodes[i].childnodes[0].childnodes[0]) + "" + "[" + String (Myxml.childnodes[0].childnodes[i].childnodes[2].childnodes[0]) + "]";
  trace (new_mc.main.text);

  //Set Text style
  btntf = new TextFormat ();
  btntf.color = 0x000000;
 & Nbsp;btntf.font = "Verdana"; Font model
  btntf.size = 12;  //font size
  new_mc.main.settextformat (btntf);

Button behavior
NEW_MC.I = i;
New_mc.onrelease = function () {
var who:number = this.i;
var link:string = myxml.childnodes[0].childnodes[who].childnodes[1].childnodes[0];
Trace (link);
GetURL (link, "_blank");
};
New_mc.onrollover = function () {
Who=this.i
This._y = Newy + (MHJ * who);
Menutf = new TextFormat ();
Menutf.color = 0xff9900;
This.main.setTextFormat (MENUTF);
};
New_mc.onrollout = function () {
Menutf = new TextFormat ();
Menutf.color = 0x0000;
This.main.setTextFormat (MENUTF);
};
}
};

It's easy to see the code above?

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.