Page 1 of 1

Libraries and Sending output back to my caller...

Posted: Fri Jan 20, 2012 6:49 pm
by kcorey
Hi All,

I'm building a little library-like bit of code to do my http gets and what not. I'd like to use callbacks to notify my object when things are finished.

Let's say I had a button that called my library:
on mouseUp
httpGet "url", "httpFinished"
end mouseUp

on httpFinished
answer "Wa-hey, I made it!"
end httpFinished

How does my library know where it could find the 'httpFinished' handler?

I didn't see anything in the User Guide about this, nor the lessons. Anyone got a FM to RT?

-Ken

Re: Libraries and Sending output back to my caller...

Posted: Fri Jan 20, 2012 6:59 pm
by mwieder
Off the top of my head, since you've got httpGet in a mouseUp handler I'll assume that httpGet is asynchronous. Otherwise you'd be better off saying

Code: Select all

dispatch "httpGet" with url,"httpFinished"
but with that out of the way, how about something at the end of httpGet like

Code: Select all

send "httpFinished" to the target

Re: Libraries and Sending output back to my caller...

Posted: Fri Jan 20, 2012 11:26 pm
by kcorey
Hiya,

Hrm...seems that the 'target' is getting lost in all the callbacks. the short name of 'target' is the name of the card upon which the script lies, not the button that originally kicked it off. Might need some sort of closure to keep the state of 'target' around.

Ah, that's the key then...if I save the 'target' in the first call, after all the callbacks I can send the callback message to the object originally clicked on.

Well done! Thanks for the pointer there.

-Ken