I'm trying to pull an XML page from Amazon (using their REST API) and it
works great from the message window, but the handler must work too fast.
When it gets to checking netDone, it isn't done yet.  Is there a way to
have it wait until it is done?   I'm not getting any netError or any other
error.  Just no nettextresult and netdone is always false.  Here's what
I've got, pretty basic:

 netID = getNetText(myURL)
 put myURL
 put netError(netID)

 if (netdone(netID)=true AND netError(netID)="OK") then
  blahblahblah
...

As you've just discovered, getNetText is an asynchronous call - meaning that lingo execution doesn't halt until a value is returned. This makes perfect sense if you think about it as there's no way to be sure, when fetching files from the internet, whether there will even be a successful result much less how long it might take. Consider downloading a 100MB file over a 56kbps connection and that your projector might appear frozen until the download is complete to understand why it works this way.
The upshot of this is that you issue a getNetText command which returns you an index for a net operation (netID). You have to then continuously monitor this netID (with netDone) until the operation is finished ( netDone(netID)= TRUE ). Once the operation is finished you can see if it succeeded or not ( netError(netID) = "OK" ). Exactly as you have above, with the exception that you (usually) have to wait until the netDone() function returns TRUE. The process of waiting and checking can be achieved in a number of different ways - by using a frame-related event in the script doing the GET, by dropping it into the actorList and checking on stepFrame, by creating a timeout object and checking from its callback, etc., etc.


Perhaps you could try:
--
property myURL
property netID

on mouseUp me
  netID = getNetText(myURL)
end

on exitFrame me
if voidP(netID) then exit
if netDone(netID) then
if netError(netID) = "OK" then
txt = netTextResult(netID)
-- whatever you need to do with the text
else
-- alert "An error occurred:" && netError(netID)
end if
end if
end



[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to