Libraries and Sending output back to my caller...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kcorey
Posts: 62
Joined: Fri Nov 25, 2011 6:06 pm

Libraries and Sending output back to my caller...

Post by kcorey » Fri Jan 20, 2012 6:49 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

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

Post by mwieder » Fri Jan 20, 2012 6:59 pm

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

kcorey
Posts: 62
Joined: Fri Nov 25, 2011 6:06 pm

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

Post by kcorey » Fri Jan 20, 2012 11:26 pm

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

Post Reply