【发布时间】:2012-03-28 08:21:23
【问题描述】:
我有一个健康提示 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 代码会很棒。
谢谢您,等待您的答复
海伦
【问题讨论】:
标签: xml actionscript-3 flash