Flash AS3 锁定每秒 XML 调用
我正在编写一个应用程序,该应用程序调用 16 个市场的价格源并将其显示在应用程序中。
在as1中没有问题,它永远不会锁定...但在as3中它可能会进行20次调用(20秒的数据)然后锁定。
我在想 as3 中是否有一个缓冲系统或类似的我不知道的东西
或任何其他想法。
这是代码
//===================================
// Package
//===================================
var priceFeedURL = "http://www.blabla.com/prices.xml";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
var myObj:Object = new Object();
//===================================
// Call XML
//===================================
function Init():void {
myTimer.start();
}
function callPriceFeed():void {
xmlLoader.load(new URLRequest(priceFeedURL));
}
function showXML(e:Event):void {
XML.ignoreWhitespace = true;
var pricesXML:XML = new XML(e.target.data);
myObj.currentPrice = pricesXML.IT[3].@BP;
PerSecondFunctions();
}
//===================================
// Timer
//===================================
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent):void {
callPriceFeed();
}
//===================================
// Per Second functions
//===================================
function PerSecondFunctions():void {
ShowPrice();
}
function ShowPrice():void {
currentPriceTXT.text = "PRICE : "+myObj.currentPrice;
trace(gnutradeObj.currentPrice+" "+Math.random());
priceGlowMC.gotoAndPlay(2);
}
Init();
谢谢
I am writing a app that calls a price feed of 16 markets and displays them in the app.
In as1 there is no issue, it never locks up... but in as3 it makes maybe 20 calls (20 seconds of data) and then locks up.
I was thinking is there a buffering system or something like that I dont know about in as3
or any other ideas.
Here is the code
//===================================
// Package
//===================================
var priceFeedURL = "http://www.blabla.com/prices.xml";
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
var myObj:Object = new Object();
//===================================
// Call XML
//===================================
function Init():void {
myTimer.start();
}
function callPriceFeed():void {
xmlLoader.load(new URLRequest(priceFeedURL));
}
function showXML(e:Event):void {
XML.ignoreWhitespace = true;
var pricesXML:XML = new XML(e.target.data);
myObj.currentPrice = pricesXML.IT[3].@BP;
PerSecondFunctions();
}
//===================================
// Timer
//===================================
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent):void {
callPriceFeed();
}
//===================================
// Per Second functions
//===================================
function PerSecondFunctions():void {
ShowPrice();
}
function ShowPrice():void {
currentPriceTXT.text = "PRICE : "+myObj.currentPrice;
trace(gnutradeObj.currentPrice+" "+Math.random());
priceGlowMC.gotoAndPlay(2);
}
Init();
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已经有一些用于异步加载多个文件的不错的解决方案(框架):
http://code.google .com/p/bulk-loader/
http://www.greensock.com/loadermax/
There are already some nice solutions (frameworks) for loading multiple files asynchronous:
http://code.google.com/p/bulk-loader/
http://www.greensock.com/loadermax/
我会参考 The_asMan 关于验证您是否确实打算每秒发送一次 HTTP 请求的评论。
我要做的是尝试一种串行请求数据的方法,主要是因为您使用全局变量来存储/呈现数据,即使您也允许同时处理多个 HTTP 请求/响应。这样,具有不同带宽能力的客户端每秒最多可以请求一次数据,而带宽较低的客户端不会因为在 UI 有机会呈现最新响应之前重新请求数据而造成体验瓶颈。
基本上,我在一秒钟停止计时器,然后在出错时或在完全/大部分处理响应后,再次启动计时器。
我的更改用
// ADDED
注释I'd refer to The_asMan's comment about verifying that you really intend for HTTP requests to be sent once a second.
What I would do is try for an approach that serially requests data, mainly because you are using global vars to store/present data even though you also allow for multiple HTTP request/responses to be handled simultaneously. In this way, clients with different bandwidth capability could request data at most once per second and clients that lower bandwidth will not bottleneck their experience by re-requesting data before the UI has had a chance to render the latest response.
Basically, I stop the timer at one second, then on error or after response has been fully/mostly handled, start up the timer again.
My changes are annotated with
// ADDED