根据日期通过flash调用XML项目

时间:2012-03-28 08:21:24

标签: xml actionscript-3 flash

我有一个健康提示flash动画,我想每天显示一个提示。 我每天创建一个包含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].@name+"-"+list[i].comments+" - "+list[i].image)
    this["Title_txt"+i].text = list.@title
    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代码会很棒。

谢谢你,等待你的回答

海伦

1 个答案:

答案 0 :(得分:0)

为什么不使用for each循环而不是常规for? 此外,var list:XMLList=myXml.title已经足够了。

..title