AS2 newbie here, and I want to know if anybody can help me with the following code. Basically what I want to do is add another field to an XML file that is already being used to populate a AS2 news scroller that I got from activeden. You will notice that I have tried duplicate the day field and add a month field in but it does not seem to be working. Any help would be greatly appreciated. My code is below.
XML:
<?xml version=".0" encoding="utf-8" ?>
<xml>
<settings
newswidth = "320"
newsheight = "390"
timer = "200"
bgAlpha = "90"
dateColor = "0xEAEAEA"
newsBgColor = "0x3E3E3E"
dateBgColor = "0x3E3E3E"
navIconColor = "0x222222"
navBgColor = "0xFFFFFF"
>
</settings>
<allnews>
<news>
<day开发者_StackOverflow中文版><![CDATA[<a href="http://activeden.net/user/designesia">01</a>]]></day>
<month>DEC</month>
<text><![CDATA[<a href="http://activeden.net/user/designesia">Recalls</a>]]></text>
<url>http://activeden.net/user/designesia</url>
<window>2</window>
</news> etc.
Actionscript:
//XML NEWS SCROLLER BY DESIGNESIA 2
stop();
var myxml = new XML();
var newsAr:Array = new Array();
var ypos = 0;
var page = 0;
var t = 0;
myxml.ignoreWhite = true;
myxml.load("news.xml");
import mx.transitions.Tween;
import mx.transitions.easing.*;
newsclip.mc._visible = false;
setColor = function(mc,varColor){
var mycolor:Color = new Color(mc);
mycolor.setRGB(varColor);
}
myxml.onLoad = function(success){
if(success){
// ===== GET GLOBAL SETTINGS FROM XML =====
settings = myxml.firstChild.childNodes[0].attributes;
mask._width = settings.newswidth;
mask._height = settings.newsheight;
bgAlpha = Number(settings.bgAlpha);
timer = Number(settings.timer);
// ===== COLOR SETTINGS =====
//dateColor = settings.dateColor;
newsBgColor = settings.newsBgColor;
dateBgColor = settings.dateBgColor;
navIconColor = settings.navIconColor;
navBgColor = settings.navBgColor;
// ===== PRE INIT =====
btnUp._alpha = bgAlpha;
btnDown._alpha = bgAlpha;
btnUp._x = mask._width - btnUp._height - 100;
btnDown._x = mask._width - btnUp._height - 140;
btnUp._y = mask._height + 18;
btnDown._y = btnUp._y;
// ===== CSS FOR TEXT =====
var style = new TextField.StyleSheet();
style.setStyle("a:link", {textDecoration:'none'});
style.setStyle("a:hover", {textDecoration:'underline'});
style.setStyle("em", {textDecoration:'underline'});
// ===== NEWS COUNT =====
total = myxml.firstChild.childNodes[1].childNodes.length;
// ===== GENERATE NEWS =====
for(i=1;i<=total;i++){
duplicateMovieClip("newsclip.mc","mc"+i,i);
newsAr[i] = eval("newsclip.mc" + i);
newsAr[i]._y = newsAr[i-1]._y + 91;
newsAr[i]._alpha = bgAlpha;
newsAr[i].bg._width = mask._width;
// ===== DATE =====
newsAr[i].date.txt.text = myxml.firstChild.childNodes[1].childNodes[i-1].childNodes[0].childNodes[0].nodeValue;
newsAr[i].date.txt.text = newsAr[i].date.txt.text.toUpperCase()
setColor(newsAr[i].bgdate,dateBgColor);
// ===== MONTH =====
newsAr[i].date.txt2.text = myxml.firstChild.childNodes[1].childNodes[i-1].childNodes[1].childNodes[0].nodeValue;
newsAr[i].date.txt2.text = newsAr[i].date.txt2.text.toUpperCase()
setColor(newsAr[i].bgdate,dateBgColor);
// ===== VARIABLE & SETTINGS FOR TEXT =====
newsAr[i].teks.txt._width = mask._width - 20;
newsAr[i].teks.txt.multiline = true;
newsAr[i].teks.txt.selectable = false;
newsAr[i].teks.txt.html = true;
newsAr[i].teks.txt.htmlText = myxml.firstChild.childNodes[1].childNodes[i-1].childNodes[2].childNodes[0].nodeValue;
newsAr[i].teks.txt.styleSheet = style;
// ===== BACKGROUND =====
//setColor(newsAr[i].bg,newsBgColor);
// ===== URL =====
newsAr[i].link = myxml.firstChild.childNodes[1].childNodes[i-1].childNodes[3].childNodes[0].nodeValue;
newsAr[i].wd = Number(myxml.firstChild.childNodes[1].childNodes[i-1].childNodes[3].childNodes[0].nodeValue);
// ===== ADD BUTTON FUNCTION =====
newsAr[i].onRelease = function(){
if(this.link<>undefined){
if(this.wd==1){
getURL(this.link,"_self");
}else{
getURL(this.link,"_blank");
}
}
} // CLOSE newsAr[i].onRelease
newsAr[i].onRollOver = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,bgAlpha,100,1,true);
}
newsAr[i].onRollOut = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,100,bgAlpha,1,true);
}
} // ===== CLOSE FOR =====
// ===== ACTION FOR NAVIGATION BUTTONS =====
// ===== SET COLOR ====
setColor(btnUp.bg,navBgColor);
setColor(btnDown.bg,navBgColor);
setColor(btnUp.ico,navIconColor);
setColor(btnDown.ico,navIconColor);
btnUp.onRelease = function(){
t = 0;
if(page>0){
page--;
ypos+=91;
var HTween1:Tween = new Tween (newsclip,"_y",Strong.easeIn,newsclip._y,ypos,.5,true);
}
}
btnUp.onRollOver = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,bgAlpha,100,1,true);
}
btnUp.onRollOut = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,100,bgAlpha,1,true);
}
btnDown.onRelease = function(){
t = 0;
if(page<total-5){
page++;
ypos-=80;
var HTween1:Tween = new Tween (newsclip,"_y",Strong.easeIn,newsclip._y,ypos,.5,true);
}else{
page = 0;
ypos = 0;
var HTween1:Tween = new Tween (newsclip,"_y",Strong.easeIn,newsclip._y,ypos,.5,true);
}
}
btnDown.onRollOver = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,bgAlpha,100,1,true);
}
btnDown.onRollOut = function(){
var HTween1:Tween = new Tween (this,"_alpha",Strong.easeOut,100,bgAlpha,1,true);
}
// ===== ROTATE THE NEWS =====
newsclip.onEnterFrame = function(){
t++;
if(t>=timer){
if(page<total-5){
page++;
ypos-=80;
var HTween1:Tween = new Tween (newsclip,"_y",Strong.easeIn,newsclip._y,ypos,.5,true);
}else{
page = 0;
ypos = 0;
var HTween1:Tween = new Tween (newsclip,"_y",Strong.easeIn,newsclip._y,ypos,.5,true);
}
t = 0;
}
}
}
}
Have you defined myxml as an variable and an XML object anywhere?
Your XML references all work for me (including the month) as soon as I add it. It should be placed before you attempt to load the XML, like below:
var myxml = new XML();
myxml.ignoreWhite = true;
myxml.load("news.xml");
精彩评论