我正在尝试创建一个列出特定按钮的场地的应用程序! 我已经创建了其他所有内容,但我正在努力创建一个函数,该函数随机化XML文件中的数据,然后在我已经设置的动态文本框中显示这些数据!数学函数可能吗?
答案 0 :(得分:0)
要从XML中获取随机值,我会这样做:
import flash.display.*;
import flash.net.*;
import flash.events.*;
var xml:XML = <venues>
<venue name="Venue A" description="A description" address="1. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://dop.com" picture="/path/to/some/picture.png" />
<venue name="Venue B" description="B description" address="2. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://google.com" picture="/path/to/some/picture.png" />
<venue name="Venue C" description="C description" address="3. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://yahoo.com" picture="/path/to/some/picture.png" />
<venue name="Venue D" description="D description" address="4. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://cnn.com" picture="/path/to/some/picture.png" />
<venue name="Venue E" description="E description" address="5. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://youtube.com" picture="/path/to/some/picture.png" />
<venue name="Venue F" description="F description" address="6. 2772 Loker Ave West, Carlsbad, CA 92010" website="http://bing.com" picture="/path/to/some/picture.png" />
</venues>;
var list:XMLList = new XMLList(xml.venue);
function getRandomVenue():void
{
var rand:int = list.length() * Math.random();
trace("Name:",list[rand].@name);
trace("Description:",list[rand].@description);
trace("Address:",list[rand].@address);
trace("Website:",list[rand].@website);
trace("Picture:",list[rand].@picture);
}
getRandomVenue();
由于我们不知道您的XML是什么样的,我猜测了 的外观。