将另一个XML字段添加到AS2脚本

时间:2010-11-24 00:20:02

标签: xml actionscript-2

AS2新手在这里,我想知道是否有人可以帮助我使用以下代码。基本上我想要做的是将另一个字段添加到XML文件中,该文件已经被用于填充我从activeden获得的AS2新闻滚动条。你会注意到我已经尝试复制day字段并添加一个月字段但它似乎没有工作。任何帮助将不胜感激。我的代码如下。

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><![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;
                }

            }
    }
}

1 个答案:

答案 0 :(得分:0)

您是否已将myxml定义为变量和XML对象?

一旦我添加它,您的XML引用我的所有工作(包括月份)。它应该在您尝试加载XML之前放置,如下所示:

var myxml = new XML();   
myxml.ignoreWhite = true;
myxml.load("news.xml");