2010-11-24 3 views
2

AS2 newbie ici, et je veux savoir si quelqu'un peut m'aider avec le code suivant. Fondamentalement, ce que je veux faire est d'ajouter un autre champ à un fichier XML qui est déjà utilisé pour remplir un explorateur de nouvelles AS2 que j'ai reçu d'activeden. Vous remarquerez que j'ai essayé de dupliquer le champ du jour et d'ajouter un champ mois, mais cela ne semble pas fonctionner. Toute aide serait grandement appréciée. Mon code est ci-dessous.Ajouter un autre champ XML au script AS2

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

      } 
    } 
} 

Répondre

0

Avez-vous défini myXML comme une variable et un objet XML partout?

Vos références XML fonctionnent toutes pour moi (y compris le mois) dès que je l'ajoute. Il doit être placé avant que vous essayez de charger le XML, comme ci-dessous:

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