2011-08-01 5 views
0

16 개 시장의 가격 피드를 호출하고 앱에 표시하는 앱을 작성 중입니다.플래시 AS3 초당 잠금 XML 호출

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][email protected]; 
    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(); 

감사

+0

을 MyTimer 초마다 timerListener를 호출 어떤 매초마다 callPriceFeed를 호출합니다. 나는 네 논리가 거기서 소리가 나는 것 같지 않아. –

+0

그게 내가 필요로하는 것입니다, XML은 매 초마다 업데이트되므로 매 초마다 호출하고 새로운 주가를 다시로드해야합니다. – gringoLoco007

+0

당신은이 서버에 부하를 걸었습니다. –

답변

0
내가 HTTP 요청 초에 한번씩 발송하는 당신이 정말 의도가 있음을 확인하는 방법에 대한 The_asMan의 의견을 참조 것

입니다.

여러 가지 HTTP 요청/응답을 동시에 처리 할 수있는 경우에도 데이터를 저장/표시하기 위해 글로벌 변수를 사용하기 때문에 데이터를 순차적으로 요청하는 방식을 시도해보십시오. 이러한 방식으로 서로 다른 대역폭 기능을 가진 클라이언트는 초당 최대 한 번씩 데이터를 요청할 수 있으며 대역폭을 줄인 클라이언트는 UI가 최신 응답을 렌더링하기 전에 데이터를 다시 요청하여 병목 현상을 일으키지 않습니다.

기본적으로 1 초에 타이머를 중지 한 다음 오류가 발생하거나 응답이 완전히 처리되었지만 타이머를 다시 시작합니다.

내 변화는 여러 파일 비동기로드에 대한 몇 가지 좋은 솔루션 (프레임 워크) 이미 있습니다 // 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(); 
} 
+0

니스, 고마워합니다. 게시 유지 – gringoLoco007