使用从XML外汇饲料在AS3? [英] Using Forex Feed from XML in AS3?
本文介绍了使用从XML外汇饲料在AS3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用货币汇率这个XML文件在我的AS3 Flash文件:
http://www.ecb.europa.eu/stats/ eurofxref / eurofxref-daily.xml
到目前为止,这是我有:
VAR与myXML:XML;
VAR myLoader:的URLLoader =新的URLLoader();
myLoader.load(新的URLRequest(http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml));
myLoader.addEventListener(引发Event.COMPLETE,的processXML);
功能的processXML(五:事件):无效{
与myXML =新的XML(e.target.data);
跟踪(与myXML *。);
}
有了这个,我得到整个XML文档作为输出。
我怎样才能联系地址不同的魔方货币,并在AS3速度的价值观?
感谢您的帮助!
解决方案
函数的processXML(五:事件):无效{
与myXML =新的XML(e.target.data);
//设置默认的xml为,这让通过名称来访问他立方节点
VAR NS:命名空间= myXML.namespace();
默认XML命名空间= NS;
//立方的节点列表
VAR列表:返回XMLList = myXML.Cube.Cube *;
VAR货币:字符串;
变种速度:数;
每个(VAR节点:XML列表中)
{
货币=字符串(节点@货币[0]);
率=节点@率[0]。
跟踪(货币,利率);
}
}
I would like to use this xml file for currency exchange rates in my AS3 flash file:
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
So far, this is what I have:
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.*);
}
With this I get the whole xml document as an output.
How can I adress the various "cube currency" and "rate" values within as3?
Thanks for your help!
解决方案
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);
}
}
这篇关于使用从XML外汇饲料在AS3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文