When I have two simultaneously active UrlLoaders, I get some weird results. In the code below, the callback function registered with the first call to my "load" function never seems to get called. The callback registered with the second call to my load function seems to get called for all url loader events, even though I've created multiple url loaders?
If I sequentialize the two calls, I don't have this problem.
function load(url, callback)
local urlLoader = UrlLoader.new(url, UrlLoader.GET)
function handleResponse(response, error)
response.url = url
response.error = error
if callback then callback(response) end
end
urlLoader:addEventListener(Event.COMPLETE, function(response) handleResponse(response, false) end)
urlLoader:addEventListener(Event.ERROR, function(response) handleResponse(response, true) end)
end
load("<a href="http://google.com"" rel="nofollow">http://google.com"</a>, function(response)
print("IN FIRST CALL FOR GOOGLE")
if response.error then
print("ERROR: loading google")
else
print("--------------- Loaded google ("..response.url..")")
print(response.data)
end
end)
load("<a href="http://apple.com"" rel="nofollow">http://apple.com"</a>, function(response)
print("IN SECOND CALL TO GOOGLE")
if response.error then
print("ERROR: loading apple")
else
print("--------------- Loaded apple ("..response.url..")")
print(response.data)
end
end) |
Results from gideros desktop player (wine running under linux):
IN SECOND CALL TO APPLE
--------------- Loaded apple (<a href="http://apple.com" rel="nofollow">http://apple.com</a>)
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="<a href="http://www.google.com/">here</A>" rel="nofollow">http://www.google.com/">here</A></a>.
</BODY></HTML>
IN SECOND CALL TO APPLE
--------------- Loaded apple (<a href="http://apple.com" rel="nofollow">http://apple.com</a>)
<head><body> This object may be found <a HREF="<a href="http://www.apple.com/">here</a>" rel="nofollow">http://www.apple.com/">here</a></a>; </body> |
Comments
But I try the following simple code,it works well,so UrlLoaders support simultaneous call.
Maybe there is a little problem with your code, I'm a newbie in lua, I can not tell what exactly it is, but It seems your callback argument in load does not associate with the urlloader object.
https://sites.google.com/site/xraystudiogame
This code works as expected.
https://sites.google.com/site/xraystudiogame
It seems just the same as in C/C++ using a global or static Variable in a function that make the function not reentrantable.
https://sites.google.com/site/xraystudiogame