How do I code "If this is a button, then ..."?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How do I code "If this is a button, then ..."?
I want my program to respond only if a button is clicked (not if clicked anywhere else). Since the action of all buttons on all cards are similar, I am trying to write a mouseUp message handler at the stack level. So I need to first make sure that if the click was received by a button. I tried
If the target is a button then .....
but it doesn't seem to be legal. So, what is the property of an object that specifies it as a button, field, menu, etc. ? Or, what's another way to achieve my objective?
Thanks,
Sri.
If the target is a button then .....
but it doesn't seem to be legal. So, what is the property of an object that specifies it as a button, field, menu, etc. ? Or, what's another way to achieve my objective?
Thanks,
Sri.
Re: How do I code "If this is a button, then ..."?
if word 1 of the target is "button" then...
Should work like a charm.
Should work like a charm.
Re: How do I code "If this is a button, then ..."?
Hi sturgis:
Thanks. Simple and clever solution!
By the way, if I use target instead of the target, it doesn't work (even though the dictionary says that both are equivalent for objects other than a field).
Regards,
Sri.
Thanks. Simple and clever solution!
By the way, if I use target instead of the target, it doesn't work (even though the dictionary says that both are equivalent for objects other than a field).
Regards,
Sri.
-
- VIP Livecode Opensource Backer
- Posts: 281
- Joined: Sat Jun 04, 2011 5:41 pm
- Location: Switzerland
Re: How do I code "If this is a button, then ..."?
Is a function so, or you use the target or you use target() ... with the parenthesis !sritcp wrote:Hi sturgis:
Thanks. Simple and clever solution!
By the way, if I use target instead of the target, it doesn't work (even though the dictionary says that both are equivalent for objects other than a field).
Regards,
Sri.
Guglielmo
Re: How do I code "If this is a button, then ..."?
Yep, as Guglielmo says, check the dictionary, you can either use THE TARGET or TARGET().
Re: How do I code "If this is a button, then ..."?
I was referring to the following, found in the Comments section under target keyword in the dictionary
If the target object is not a field, the target keyword reports the name of the object, just like the target function.
I found that it does not; target keyword reports nothing; the message box is blank. (The target function works, of course).
This is what I was trying to convey.
Regards,
Sri.
If the target object is not a field, the target keyword reports the name of the object, just like the target function.
I found that it does not; target keyword reports nothing; the message box is blank. (The target function works, of course).
This is what I was trying to convey.
Regards,
Sri.
Re: How do I code "If this is a button, then ..."?
Hmm interesting.
If I put a mouseup handler into the card, then drop a button and a field onto the card
And the mouseup handler is as follows
on mouseUp
put target
end mouseUp
It works exactly as described. If I click the text field (with text in it, and with the locktext set to true) it displays the contents of the field in the msg box. If I click the button (and there is no mouseup handler in it) it displays the button name.
So the most likely answer is your field is not locked, so when yuo click it there is no mousup sent, instead the insertion point is placed at the location of the mouse click.
From the mouseup dictionary entry
If I put a mouseup handler into the card, then drop a button and a field onto the card
And the mouseup handler is as follows
on mouseUp
put target
end mouseUp
It works exactly as described. If I click the text field (with text in it, and with the locktext set to true) it displays the contents of the field in the msg box. If I click the button (and there is no mouseup handler in it) it displays the button name.
So the most likely answer is your field is not locked, so when yuo click it there is no mousup sent, instead the insertion point is placed at the location of the mouse click.
From the mouseup dictionary entry
The mouseUp message is sent only when the Browse tool is being used. If an unlocked field is clicked with mouse button 1 or 2, no mouseUp message is sent.
Re: How do I code "If this is a button, then ..."?
Yes, but not if you trysturgis wrote: .............
on mouseUp
put target
end mouseUp
It works exactly as described...........
put word 1 of target
I guess "word 1 of" doesn't work with target but does with the target.
(By the way, I tried only with a button; so the "lockedText" explanation, while valid, didn't apply in my case)
Regards,
Sri.
Re: How do I code "If this is a button, then ..."?
That is a bit weird, and I finally see what you're talking about.
of course for what you're trying to do using the function is a better choice either way, however to make it work as expected with the keyword rather than function you can do this
put word 1 of (target) -- force target to be completely evaluated first
Good catch, it SHOULD work as you say. I just always use target() or the target so this is a new one on me!
of course for what you're trying to do using the function is a better choice either way, however to make it work as expected with the keyword rather than function you can do this
put word 1 of (target) -- force target to be completely evaluated first
Good catch, it SHOULD work as you say. I just always use target() or the target so this is a new one on me!
Re: How do I code "If this is a button, then ..."?
And it works! And, I learned something today!sturgis wrote:......
put word 1 of (target) -- force target to be completely evaluated first
Thanks,
Sri.
Re: How do I code "If this is a button, then ..."?
So did I!sritcp wrote:And it works! And, I learned something today!sturgis wrote:......
put word 1 of (target) -- force target to be completely evaluated first
Thanks,
Sri.
-
- VIP Livecode Opensource Backer
- Posts: 7241
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How do I code "If this is a button, then ..."?
It's historical syntax dating back to HyperCard. The keyword "target" (without "the" or parentheses) refers to the text content of a field.
If you click on a field:
put target -- field text content
put the target -- "field x of stack y"
If you click on a field:
put target -- field text content
put the target -- "field x of stack y"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com