xml| Program | Paging Flash calls an external XML program to display the news, when the news has reached a certain number of paging problems, think about it today, there are probably two ways to implement, the first is relatively simple, first get the number of the XML file, and then divided by the number of entries to display, You can tell how many pages there are, then by calling every page of news to achieve the paging effect, such as: 10 news per page, XML file a total of 36 news, then should display 4 pages, that is, Math.floor (36/10) +1, so there is a problem, assuming that the number of news n just in line with n% 10==0 condition, this time the page should not add 1, I began to ignore the problem, in doing
"The World"The official website found that the above news bar number is just 10, so there is an empty page, to make a judgment can avoid this problem.
Now step by step to achieve, first in the scene to create a new MC named News_a, which contains a dname dynamic text box to display the data in the XML, OK, with the Duplicatemovieclip function copy 10 news_a to display the call of 10 news, At this point, if the number of pages is greater than 1, you will also need to display the next Page button for page loading, and, if there is a previous page, you need to display the previous page button to load the page. Name the next page button NEXTP, the previous page button is Previousp, and the state of both buttons is not visible by default.
Suppose that the XML file for the external file news is news.xml, the specific procedure is as follows:
var news_xml:xml = new XML ();
News_xml.onload = function (Success:boolean): Void {
if (success) {//load XML file succeeded
var newsitems:array = news_xml.firstChild.childNodes;
(newsitems.length%10 = 0)? (var pages:number = Math.floor (NEWSITEMS.LENGTH/10)):(var pages = Math.floor (NEWSITEMS.LENGTH/10) +1);//Judge pages
if (pages>1) {
Nextp._visible = true;//If the number of pages is greater than 1, the next page button is displayed
}//This article original, reprint please indicate the source! (http://www.xiacong.com)
for (var i:number = 0; i<10; i++) {//Initial state load latest 10 News
News_a.duplicatemovieclip ("NA" +i, i+1000);
With (eval ("NA" +i)) {
_x = 0;
_y = 0+i*24;
if (newsitems[i].firstchild.firstchild.nodevalue!=null) {
This.dname.text = Newsitems[i].firstchild.firstchild.nodevalue;
This.id = i;
This.onrollover = Menuover;
This.onrelease = Menurelease;
This.onrollout = Menuout;}
}
}
} else {
News_a.dname.text = "News load Failed";
}
};
News_xml.load ("News.xml"); The code on the path that loads the external XML file has loaded the default latest 10 news, now for the paging load, there are two functions: previous page function previouspages () and the next page function nextpages ();
The principle of the previous page and the next page is: When you click on "Next Page", use Removemovieclip () to uninstall all the content shown before (this in order to save CPU and memory consumption), when clicked "Previous page", also want to uninstall the previous display of content, The new news item is then loaded into a dynamic text box using functions similar to the code above, and the Function procedure is as follows:
function Nextpages () {
++page;
var newsitems:array = news_xml.firstChild.childNodes;
(newsitems.length%10 = 0)? (var pages:number = Math.floor (NEWSITEMS.LENGTH/10)):(var pages = Math.floor (NEWSITEMS.LENGTH/10) +1);//Judge pages
if ((page+1) = pages) {
Nextp._visible = false;
}
if (page!= 0) {
Previousp._visible = true;
}//This article original, reprint please indicate the source! (http://www.xiacong.com)
for (P = p<10; p++) {
Removemovieclip ("NA" + ((page-1) *10+p));
Trace ("NA" + ((page-1) *10+p));
News_a.duplicatemovieclip ("NA" + (page*10) +p), (page*10) +p+1000);
Eval ("NA" + ((page*10) +p)). _x = 0;
Eval ("NA" + ((page*10) +p)). _y = 0+p*24;
if (newsitems[(page*10) +p].firstchild.firstchild.nodevalue!=null) {
Eval ("NA" + ((page*10) +p)). Dname.text = newsitems[(page*10) +p].firstchild.firstchild.nodevalue;
Eval ("NA" + ((page*10) +p)). id = (page*10) +p;
Eval ("NA" + ((page*10) +p)). Onrollover = Menuover;
Eval ("NA" + ((page*10) +p)). Onrelease = Menurelease;
Eval ("NA" + ((page*10) +p)). Onrollout = Menuout;}
}
}function Previouspages () {
--page;
var newsitems:array = news_xml.firstChild.childNodes;
(newsitems.length%10 = 0)? (var pages:number = Math.floor (NEWSITEMS.LENGTH/10)):(var pages = Math.floor (NEWSITEMS.LENGTH/10) +1);//Judge pages
if (page = = 0) {
Previousp._visible = false;
}
if ((page+1)!= pages) {
Nextp._visible = true;
}//This article original, reprint please indicate the source! (http://www.xiacong.com)
for (P = p<10; p++) {
Removemovieclip ("NA" + ((page+1) *10+p));
Trace ("NA" + ((page+1) *10+p));
News_a.duplicatemovieclip ("NA" + (page*10) +p), (page*10) +p+1000);
Eval ("NA" + ((page*10) +p)). _x = 0;
Eval ("NA" + ((page*10) +p)). _y = 0+p*24;
Eval ("NA" + ((page*10) +p)). Dname.text = newsitems[(page*10) +p].firstchild.firstchild.nodevalue;
Eval ("NA" + ((page*10) +p)). id = (page*10) +p;
Eval ("NA" + ((page*10) +p)). Onrollover = Menuover;
Eval ("NA" + ((page*10) +p)). Onrelease = Menurelease;
Eval ("NA" + ((page*10) +p)). Onrollout = Menuout;
}
}ok, paging all realize! The above code in the menurelease;menuover;menuout represents the mouse action, hehe ~ When the mouse is put up to display different colors, click to link to the details of the news page ~ ~
function Menuover () {
Eval ("NA" +this.id). Dname.textcolor = "0xFFFFFF";
}
function Menuout () {
Eval ("NA" +this.id). Dname.textcolor = "0XFDE5B9";
}
function Menurelease () {
var url_link = News_xml.firstchild.childnodes[this.id].childnodes[1].firstchild.nodevalue;
if (Url_link!= null) {
GetURL ("Javascript:void (Open_window)" ("+url_link+"));
}
Finally finished, we can test, I try to use easy to understand the way of thinking and procedures to achieve the paging effect, which is NetEase
"The World"Online official website Flash load external XML to achieve the source code of the news, hehe ~
Another way to think about it, because each page loads a fixed amount of news items, such as 10, then the first page is displayed 1-10, the second page shows 11-20, and so on, you can use the page variable p*10+ (0-10) to load, 1, 11, 21, 31 ... These are placed in the same area, so relatively easy to achieve, interested can try ~ ~ hehe
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.