상세 컨텐츠

본문 제목

ActionScript URLLoader의 internet explorer ie8,9,10,11 버전등등 같은 url로 로드했을때 값이 같은 값이 나왔을때 문제관련 URLLoader.load() issue when using the same URLRequest , I have an issue with my eventListeners with the UR..

ADOBE/ ActionScript

by AlrepondTech 2014. 10. 8. 00:06

본문

반응형
728x170

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

출처: http://stackoverflow.com/questions/3000299/urlloader-load-issue-when-using-the-same-urlrequest

 

public function getUploadURL():void { var request:URLRequest = new URLRequest(); request.url = getPath(); request.method = URLRequestMethod.GET; _loader = new URLLoader(); _loader.dataFormat = URLLoaderDataFormat.TEXT; _loader.addEventListener(Event.COMPLETE, getBaseURL); _loader.load(request); } private function getBaseURL(event:Event):void { _loader.removeEventListener(Event.COMPLETE, getBaseURL); }
The issue is that my getBaseURL gets executed automatically after I have executed the code at least once, but that is the case only in IE. What happens is I call my getUploadURL, I make sure the server sends an event that will result in an Event.COMPLETE, so the getBaseURL gets executed, and the listener is removed. If I call the getUploadURL method and put the wrong path, I do not get an Event.COMPLETE but some other event, and getBaseURL should not be executed.
That is the correct behavior in FireFox. In IE, it looks like the load() method does not actually call the server, it jumps directly to the getBaseURL() for the Event.COMPLETE. I checked the willTrigger() and hasEventListener() on _loader before assigning the new URLLoader, and it turns out the event has been well removed.
I hope I make sense, I simplified my code. To sum up quickly: in FireFox it works well, but in IE, the first call will work but the second call won't really call the .load() method; it seems it uses the previously stored result from the first call.
I hope someone can please help me, Thank you,
Rudy
share|improve this question
 

2 Answers

Try adding a random variable to the url to prevent caching.
var url:String = getPath(); //if path already contains some variables, replace ? with & url += "?random=" + Math.random(); request.url = getPath();
share|improve this answer
 
    
Your solution fixed my issue! Thanks. So this has to do with caching. But what happens if the Math.random() gives the same result? Then it will use the cached URLRequest no?! Is there any way I can force it to not cache. The solution using URLRequestHeader did not work unfortunately. Thanks a lot though. –  Rudy Jun 9 '10 at 15:49
1  
@Rudy the chances of Math.random giving same results within same session (before cache is cleared), is very small; but if you really want to make sure, you can use the current time - the number of milliseconds passed since linux epoch. url += "?random=" + (new Date()).getTime(); –  Amarghosh Jun 10 '10 at 4:05
    
Thank you, I will use the getTime() function, that's a very good idea. Thanks a lot! –  Rudy Jun 10 '10 at 15:54
Possibly the request has been cached.
var hdr:URLRequestHeader = new URLRequestHeader("pragma", "no-cache"); .... request.requestHeaders.push(hdr);
share|improve this answer
 
    
Thanks, I just tried but unfortunately it has made no difference. –  Rudy Jun 8 '10 at 19:23
    
@Ruby check out edits. –  hardik Sep 5 '11 at 5:50

 

 

 

 

=================================

=================================

=================================

 

 

 

액션 스크립트에서 url 로드 할때 ms의 인터넷익스플로어에서 값이 바꾸어 지지않는 현상이 일어나면 위와 같이 해결 해도 되지만

html 코드에 no-cache 을 추가 해서 값이 바꾸어지나 확인해 보는 것도 한가지 방법 입니다. 

 

 

=================================

=================================

=================================

 

 

 

반응형
그리드형


관련글 더보기

댓글 영역