【问题标题】:Using Forex Feed from XML in AS3?在 AS3 中使用来自 XML 的外汇提要?
【发布时间】:2013-01-16 19:52:03
【问题描述】:

我想在我的 AS3 flash 文件中使用这个 xml 文件来计算货币汇率:

http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

到目前为止,这就是我所拥有的:

var myXML:XML;
var myLoader:URLLoader = new URLLoader();

myLoader.load(new URLRequest("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));
 myLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.*);
}

有了这个,我得到了整个 xml 文档作为输出。

如何处理 as3 中的各种“立方体货币”和“汇率”值?

感谢您的帮助!

【问题讨论】:

    标签: xml actionscript-3 flash


    【解决方案1】:
        function processXML(e:Event):void {
            myXML = new XML(e.target.data);
    
            //set default xml to "", this allow to access to he Cube nodes by name
            var ns:Namespace =  myXML.namespace("");
            default xml namespace = ns;
    
            //list of Cube nodes
            var list:XMLList = myXML.Cube.Cube.*;
            var currency:String;
            var rate:Number;
            for each(var node:XML in list)
            {
                currency = String(node.@currency[0]);
                rate = node.@rate[0];
                trace(currency, rate);
            }
        }       
    

    【讨论】:

    • 太棒了,谢谢!我是否可以在文本字段中显示单个值(即仅 USD 及其值)?干杯!
    • 是的,当然,if(currency == "USD") myTextField.text = String(rate)。如果它解决了您的问题,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多