Flash AS3 锁定每秒 XML 调用

发布于 2024-11-27 03:19:55 字数 1479 浏览 0 评论 0原文

我正在编写一个应用程序,该应用程序调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小耗子 2024-12-04 03:19:55

已经有一些用于异步加载多个文件的不错的解决方案(框架):

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/

桃扇骨 2024-12-04 03:19:55

我会参考 The_asMan 关于验证您是否确实打算每秒发送一次 HTTP 请求的评论。

我要做的是尝试一种串行请求数据的方法,主要是因为您使用全局变量来存储/呈现数据,即使您也允许同时处理多个 HTTP 请求/响应。这样,具有不同带宽能力的客户端每秒最多可以请求一次数据,而带宽较低的客户端不会因为在 UI 有机会呈现最新响应之前重新请求数据而造成体验瓶颈。

基本上,我在一秒钟停止计时器,然后在出错时或在完全/大部分处理响应后,再次启动计时器。

我的更改用 // ADDED 注释

xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

// ADDED - restart (or maybe don't restart?) on error
function errorHandler(e:Event):void{
   // log and/or show error?
   if(!myTimer.running)
       myTimer.start(); //start up again and hope for the best
}

function timerListener(e:TimerEvent):void {
    // ADDED - stop timer and resume it after showXML (or error handler) has handled the response
    myTimer.stop();
    callPriceFeed();
}


function ShowPrice():void {
    currentPriceTXT.text = "PRICE : "+myObj.currentPrice;
    trace(gnutradeObj.currentPrice+" "+Math.random());
    priceGlowMC.gotoAndPlay(2);
    // ADDED - data from response ought to have migrated to the UI, now start up timer again
    if(!myTimer.running)
        myTimer.start();
}

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

xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

// ADDED - restart (or maybe don't restart?) on error
function errorHandler(e:Event):void{
   // log and/or show error?
   if(!myTimer.running)
       myTimer.start(); //start up again and hope for the best
}

function timerListener(e:TimerEvent):void {
    // ADDED - stop timer and resume it after showXML (or error handler) has handled the response
    myTimer.stop();
    callPriceFeed();
}


function ShowPrice():void {
    currentPriceTXT.text = "PRICE : "+myObj.currentPrice;
    trace(gnutradeObj.currentPrice+" "+Math.random());
    priceGlowMC.gotoAndPlay(2);
    // ADDED - data from response ought to have migrated to the UI, now start up timer again
    if(!myTimer.running)
        myTimer.start();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文