Flash+xml realizes news system

Source: Internet
Author: User
Tags date html tags set time
Xml| News System

You can learn from this example:
1> How to load and parse xml;2> how to format text with Textfield.stylesheet
Look at the structure of the XML first:

<?xml version= "1.0" encoding= "UTF-8"?>
<csdeny>
<news date= "2006-02-03" title= "State Councilor Zhili" ><content>4 month 5th afternoon, State Councilor Zhili, Minister of Education </content></news>
<news date= "2006-02-03" title= "all Hair" ><content> Chinese tofu against the broad General Assembly against arc lamp Law </content></news>
<news date= "2006-02-03" title= "This is" ><content> our tofu against the broad General Assembly against arc lamp Law </content></news>
<news date= "2006-02-03" title= "tofu" ><content> Chinese tofu against the broad General Assembly against arc lamp Law </content></news>
<news date= "2006-02-03" title= "also extra" ><content> our tofu against the broad General Assembly against arc lamp Law </content></news>
<news date= "2006-02-03" title= "Shi da" ><content> our country tofu against the broad General Assembly against arc lamp Law </content></news>
<news date= "2006-02-03" title= "method" ><content> China tofu against the broad General Assembly against arc lamp Law </content></news>
</csdeny>

Here's how it works in Flash:
1> Create a new flash document, set the stage size (My settings are 150*200)
2> drag a textarea component into the stage, set the size and stage of the same size, instance named Mytextarea;
3> add code to the first frame:

var mystyles:textfield.stylesheet=new textfield.stylesheet ()//Declare Mystyles as StyleSheet class
Mystyles.setstyle (". Title",//Set caption display style
{fontFamily: ' song body, _sans ',
FontSize: ' 12px ',
Color: ' #003300 ',
TextAlign: ' Left '});
Mystyles.setstyle (". Date",//Set time display style
{fontFamily: ' Arial ',
FontSize: ' 9px ',
Color: ' #990000 ',
TextAlign: ' Right '};
Mystyles.setstyle (". Content",//set content display style
{fontFamily: ' song body, _sans ',
FontSize: ' 12px ',
Color: ' #003300 ',
TextAlign: ' Left '});
var newsxml:xml=new XML (); DECLARE XML class
Newsxml.ignorewhite=true; Ignore whitespace
Newsxml.onload=function (Success) {
if (success) {
Parsexml (); Call Parsexml () to parse XML if the XML is successfully loaded
}
}
Newsxml.load ("News.xml"); Loading external XML
The definition of function parsexml () {//parsexml ()
var e=newsxml.firstchild.childnodes;
var total=e.length;
Mytextarea.wordwrap=true; Set up textarea to wrap lines automatically
Mytextarea.editable=false; TextArea not editable
Mytextarea.hscrollpolicy=off; TextArea horizontal scroll bar close
Mytextarea.html=true; Supports XML
Mytextarea.stylesheet=mystyles; Call the previously set style
for (i=0;i<total;i++) {//parse XML and Format text
mytextarea.text+= "<.title>" +e[i].attributes.title+ "</.title>";
mytextarea.text+= "<.date>" +e[i].attributes.date+ "</.date>";
mytextarea.text+= "<.content>" +e[i].firstchild.firstchild.nodevalue+ "</.content><br>";
}
}

All right, that's easy.
PS: Can be extended to the mystyles, Flash support of the HTML tags are many:

Click here to download the source file

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.