Xml AS3复制函数

Xml AS3复制函数,xml,actionscript-3,flash,function,duplicates,Xml,Actionscript 3,Flash,Function,Duplicates,所以我很少使用这段代码,并尝试复制它,这样flashtip2的动态文本将显示与xml不同的值,如:return Math.floorMath.random*0+0+0+13;-在动态文本flashtip2上。我怎样才能在没有重复值错误的情况下复制它?我的代码是: var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML = new XML(); xmlLoader.addEventListener(Event.COMPLETE, Lo

所以我很少使用这段代码,并尝试复制它,这样flashtip2的动态文本将显示与xml不同的值,如:return Math.floorMath.random*0+0+0+13;-在动态文本flashtip2上。我怎样才能在没有重复值错误的情况下复制它?我的代码是:

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://www.cbbh.ba/kursna_bs.xml"));

/* This loads the XML */
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseData(xmlData);
 }

 /* This gets the data for today's tip */
 function parseData(mTip:XML):void {

     var itemXMLList:XMLList = XMLList(mTip..item);
     var count:int = itemXMLList.length();
     var finalcount:int = count - 1;
     //trace(finalcount);

 function randomRange(minNum:Number, maxNum:Number):Number 
 {
return (Math.floor(Math.random() * (0 + 0 + 0)) + 12);  //+ 12 or 13 
 }
 var randomNum = randomRange(0, finalcount);
 trace(randomRange(11, 11));

 flashTip.htmlText = mTip.channel.item[randomNum].description.text();

 }
按货币获取节点

要获得具有所需货币的确切节点,可以按货币代码进行搜索。如果列表中找不到币种,函数返回null

function getNodeByCurrency(currency:String, currencyData:XML):XML {
    var items:XMLList = currencyData..item;
    var i:uint, len:uint = items.length();

    for (i; i < len; ++i) {
        if (String(items[i].title).indexOf(currency) != -1) {
            return items[i];
        }
    }

    //Currency isn't found
    return null;
}
从预定义范围中获取随机值

如果要从范围中选择随机值,则应稍微更改函数:

function randomValueFromRange(minValue:int, maxValue:int):int {
    return minValue + Math.random() * (maxValue - minValue);
}
没有重复值的错误

如果要从“生成唯一值”范围中排除某些值,可以传递上一个值:

function randomValueWithExclude(minValue:int, maxValue:int, excludeValue:int):int {
    var result:int = randomValueFromRange(minValue, maxValue);
    while (result == excludeValue) {
        result = randomValueFromRange(minValue, maxValue);
    }
    return result;
}
下面是如何使用它的示例。每8秒显示一次新提示,这与以前的提示不同:

var timer:Timer = new Timer(8000);
var count:int = itemXMLList.length();
var currentValue:int = -1;
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(e:TimerEvent):void {
    currentValue = randomValueWithExclude(0, count, currentValue);
    flashTip.htmlText = mTip.channel.item[currentValue].description.text();
}

我不是想得到随机数,而是具体的一个。我从:获取数据,在动态文本字段Jedinica:1 Kupovni za Device:0.64000897 Srednji za Device:0.641613 Prodajni za Device:0.64321703中看起来是这样的,所以我需要另一个文本框来显示相同的信息,但数字不同,所以这是土耳其货币的兑换列表,例如,我需要另一个文本框用于美国等等…如何安排这个我喜欢这个文本格式我只需要将动态文本复制到flashtip2,3,4,5中,包含美国、土耳其、中国的数据…我将使用动态文本框将它们放置在舞台上我想要的位置,但包含特定数据,以便美国将位于土耳其旁边,等等…我明白了。所以,您想知道,在XML中,关于USD或CAD的信息到底位于什么位置?因此,你将能够提取它并放置你想要的任何东西。
var timer:Timer = new Timer(8000);
var count:int = itemXMLList.length();
var currentValue:int = -1;
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(e:TimerEvent):void {
    currentValue = randomValueWithExclude(0, count, currentValue);
    flashTip.htmlText = mTip.channel.item[currentValue].description.text();
}