2012-03-28 40 views
0

我有一個健康提示Flash動畫,我想每天顯示一個提示。 我創建了一個xml,每天365項。現在我想用xml鏈接我的閃光燈,以獲得特定日期的正確提示。根據日期通過flash調用XML項目

我用兩種方法創建了XML ..你認爲哪一個最好?

<data> 

<Tip date="28/03/2012" title="Start your day with breakfast." description="Breakfast fills your empty tank to get you going after a long night without food. "/> 

</data> 

而另一個XML

<data> 
<title name="Start your day with breakfast."> 
    <description>Breakfast fills your "empty tank" to get you going after a long night without food. </description> 
</title> 

<title name="Eat more grains, fruits and vegetables."> 
    <description>These foods give you carbohydrates for energy, plus vitamins, minerals and fiber. Besides, they taste good! Try breads such as whole-wheat, bagels and pita. </description> 
</title> 

</data> 

現在我需要編寫我的Flash影片得到它的工作,但不幸的是不知道怎麼辦。

我開始與一些基本的東西:

var my_date:Date = new Date(); 

var months:Array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; 

var dateStr = ((months[my_date.month]).toString())+"_"+ my_date.date.toString()+"_"+ my_date.fullYear.toString(); 

//Create the loader, set dataFormat to text 
var loadFile:URLLoader = new URLLoader() 
loadFile.dataFormat = URLLoaderDataFormat.TEXT 
loadFile.addEventListener(Event.COMPLETE, onLoadXML) 
loadFile.load(new URLRequest("flash1.xml")); 
function onLoadXML(ev:Event){ 
try{ 
    //Convert the downloaded text into an XML 
    var myXML:XML = new XML(ev.target.data) 
    var list:XMLList = myXML..title 
    //walks the list and show in textfields 
    for(var i=0; i<list.length(); i++){ 
     //trace(list[i][email protected]+"-"+list[i].comments+" - "+list[i].image) 
    this["Title_txt"+i].text = [email protected] 
    this["description_txt"+i].text = list.description 


    } 
} catch (e:TypeError){ 
    //Could not convert the data 
    trace("Could not parse the XML") 
    trace(e.message) 
} 
} 

我不能讓它正常工作,從而尋求幫助。如果你請幫我解決日期問題,as3代碼會很棒。

謝謝你,等待你的回答

海倫

回答

0

爲什麼不使用for each循環,而不是一個普通for? 另外,var list:XMLList=myXml.title是夠好的。不需要..title

function onLoadXML(ev:Event){ 
try{ 
    //Convert the downloaded text into an XML 
    var myXML:XML = new XML(ev.target.data); 
    var list:XMLList = myXML.title; 
    //walks the list and show in textfields 
    for each(var title:XML in list){ 
     this["Title_txt"+i].text = [email protected] 
     this["description_txt"+i].text = title.description; 
    } 
} catch (e:TypeError){ 
    //Could not convert the data 
    trace("Could not parse the XML") 
    trace(e.message) 
} 
} 
+0

謝謝你的回答......這使得它在某種程度上更簡單的...雖然我仍然有日期功能的問題加載特定日期 – 2012-03-28 12:04:45

+0

好了,你的代碼顯示,你甚至不嘗試做日期的事情。我不知道你想用「日期函數」來做什麼。你爲什麼不詳細說明? – 2012-03-28 16:42:22