XML將使數據模型對您的目標直觀。
<?xml version="1.0" encoding="UTF-8"?>
<questions>
<question day="1"><![CDATA[ <b>Question 1</b>: Lorem ipsum dolor sit amet. ]]></question>
<question day="2"><![CDATA[ <b>Question 2</b>: Consectetur adipiscing elit. ]]></question>
<question day="3"><![CDATA[ <b>Question 3</b>: Duis semper risus nec nisi elementum. ]]></question>
</questions>
在ActionScript中,獲得當年的當天可以實現爲:
public static function getDayOfTheYear(d:Date):uint {
var firstDay:Date = new Date(d.getFullYear(), 0, 1);
return (d.getTime() - firstDay.getTime())/86400000;
}
一旦XML被裝載,就可以使用E4X來獲得當前問題的節點:
var now:Date = new Date();
var day:uint = getDayOfTheYear(now);
/* Assuming you loaded XML to a variable: var xml:XML */
var question:XMLList = xml.question.(@day == day);
trace(question.valueOf());
閏年的好點;謝謝。我將使用XML,我喜歡能夠以結構化方式添加附加項的想法。 – Stephen 2012-07-30 21:46:46