-1

我正在尝试创建一个列出特定按钮场所的应用程序!我已经创建了其他所有内容,但我正在努力创建一个函数,该函数将 XML 文件中的数据随机化,然后在我已经设置的动态文本框中显示这些数据!数学函数可能吗?

4

1 回答 1

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 是什么样子,所以我猜测了它的外观

于 2012-11-15T23:27:39.830 回答