2011-04-06 2 views
0

나는이 간단한 플래시 CS5/액션 스크립트 3 프로그램과 XML 파일을로드 :URLStream.connected가 항상 true입니까?

import flash.net.*; 

var URL_REQUEST:URLRequest = new URLRequest('http://preferans.de/top-xml.php'); 
var URL_STREAM:URLStream = new URLStream(); 
var URL_VARS:URLVariables = new URLVariables(); 
var UPDATE_TIMER:Timer = new Timer(1000); 

stop(); 

UPDATE_TIMER.addEventListener(TimerEvent.TIMER, handleTimer); 
UPDATE_TIMER.start(); 

URL_REQUEST.method = URLRequestMethod.GET; 
URL_REQUEST.data = URL_VARS; 

URL_STREAM.addEventListener(IOErrorEvent.IO_ERROR, handleUserError); 
URL_STREAM.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleUserError); 
URL_STREAM.addEventListener(Event.OPEN, handleUserOpen); 
URL_STREAM.addEventListener(ProgressEvent.PROGRESS, handleUserData); 
URL_STREAM.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleUserStatus); 
URL_STREAM.addEventListener(Event.COMPLETE, handleUserComplete); 
URL_STREAM.load(URL_REQUEST); 

function handleUserOpen(event:Event):void { 
    trace('handleUserOpen: ' + event); 
} 

function handleUserData(event:Event):void { 
    trace('handleUserData: ' + event); 
} 

function handleUserStatus(event:HTTPStatusEvent):void { 
    trace('handleUserStatus: ' + event.status); 
} 

function handleUserError(event:Event):void { 
    trace('handleUserError: ' + event); 
} 

function handleUserComplete(event:Event):void { 
    trace('handleUserComplete: ' + event); 

    try { 
     var str:String = URL_STREAM.readUTFBytes(URL_STREAM.bytesAvailable); 
     var xml:XML = new XML(str); 
     trace(xml); 
    } catch(e:Error){ 
     trace('Invalid data: ' + e); 
     return; 
    } 
} 

function handleTimer(event:TimerEvent):void { 
    var now:int = getTimer(); 

    trace(UPDATE_TIMER.currentCount + ' ' + now + ' ' + URL_STREAM.connected); 
} 

를 잘 작동하고 나는 XML 콘텐츠를 볼 수 있습니다

handleUserOpen: [Event type="open" bubbles=false cancelable=false eventPhase=2] 
handleUserData: [ProgressEvent type="progress" bubbles=false cancelable=false eventPhase=2 bytesLoaded=2390 bytesTotal=2390] 
handleUserStatus: 200 
handleUserComplete: [Event type="complete" bubbles=false cancelable=false eventPhase=2] 
<pref> 
    [ .... XML content .....] 
</pref> 
1 1054 true 
2 2054 true 
3 3054 true 
4 4054 true 
5 5054 true 
..... 
90 90054 true 
91 91054 true 

을하지만 난 이해가 안 돼요, 왜 URLStream.connected 항상 사실입니다.

심지어 웹 서버에서 아파치를 재시작해도 아무런 변화가 없습니다.

내 프로그램에서 Comet-like (일명 HTTP 푸시) 호출을 구현할 계획이므로 URLStream이 계속 작동 중이거나 완료/중단되어있을 수있는 경우 알 필요가 있으므로이 질문을하고 있습니다. 새로운 load() 호출을 위해 재사용합니다. (그것에 대한 workaround 상태 변수를 도입하고 싶지 않습니다.)

감사합니다. Alex

답변

1

URLStream을 사용하면 다운로드가 시작되지 않았거나 무언가 다운로드가 완료된 후에도 연결이 유지되는 파일에 액세스하는 것으로 생각합니다. 그래서 당신이 .close() 수동으로 값을 읽은 후 .COMPLETE 함수에서 생각해야합니다.

관련 문제