Collecting button names
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Collecting button names
In my stacks, I would like to know the name of each button that is clicked (mouseUp). I know how to get the short name of the button. No problem with that. But, this is in retrospect and I don't want to go back to each button in the stack and write the script or to write a "pass mouseUp" in the buttons' script. Is there a script that would allow me to get this info even though I have already created the buttons and their scripts?
I have been trying myself to find the info...I promise.
TIA,
Linda
I have been trying myself to find the info...I promise.
TIA,
Linda
Re: Collecting button names
in the stack script, you'd be looking for the target (if I understand your post correctly).
So, you know (because you wrote pass mouseUp I am guessing here) that any button without a mouseUp script will just pass that message along until it ultimately hits the main stack (see or look for 'message path' in the lessons area).
In the stack, you can write a simple handler like -
...which will only fire if no other mouseUp has happened before it reached the stack, and this is what you would see -
So, you know (because you wrote pass mouseUp I am guessing here) that any button without a mouseUp script will just pass that message along until it ultimately hits the main stack (see or look for 'message path' in the lessons area).
In the stack, you can write a simple handler like -
Code: Select all
on mouseUp
if word one of the target is "button" then answer the short name of the target
end mouseUp

Re: Collecting button names
I don't have "pass mouseUp" in the card or button scripts. That is what I was trying to avoid. This will only be used during development. So, I wanted the scripts to be only in one place so that I can delete them or comment them out later.
Hmm...Why is it that I often search and search for an answer, then I decide to ask the question here and then...I find the answer myself. Hmm.

Thanks for "listening" to me.
BTW, I put this into the stack's scripts and it is working. I am absolutely sure that there is a less cumbersome way to collect this info and store it. But, it will work for me. As I wrote, it is just during development that I will need it.
Code: Select all
global gPreviousCard, gMouseClickName
on preOpenStack
put empty into gPreviousCard
end preOpenStack
on mouseDown
put the short name of the target into gMouseClickName
end mouseDown
on closeCard
local tTextFromFile
open file specialFolderPath("desktop") & "/CardHistory.txt" for read
read from file specialFolderPath("desktop") & "/CardHistory.txt" until EOF
put it into tTextFromFile
close file specialFolderPath("desktop") & "/CardHistory.txt"
put the short name of this card into gPreviousCard
open file specialFolderPath("desktop") & "/CardHistory.txt" for write
write tTextFromFile & cr & gPreviousCard && gMouseClickName to file specialFolderPath("desktop") & "/CardHistory.txt"
close file specialFolderPath("desktop") & "/CardHistory.txt"
end closeCard
Re: Collecting button names
Yes, I think maybe I wasn't as clear as I could have been.
I'll try again

When you have a button or other object that doesn't have a script attached to it, the message that would normally be acted upon moves down the message path to the next object that it might act upon, until (if it doesn't hit anything else) it reaches the main stack.
As an example, let us say you have a stack, card, and button (keeping this simple). Your button has no 'mouseUp' handler script, but your card does. When you click on the button, without any script at all in it, the mouseUp will trigger on the card.
To further this example, your button and card have no mouseUp script, but the stack does (like the one I posted above). You click the button, the message looks at the script on the card, doesn't see a handler for mouseUp, and moves down to the stack where it is handled by the script I showed you. All of this is done without putting 'pass mouseUp' anywhere either in the buttton, or the card.
To complete this example, any button you *have* a script in, the mouseUp will trigger in that button and, unless you specifically put 'pass mouseUp', that is where it will stop.
So, to satisfy your goal of wanting any buttons that don't have a script in their object naming itself when you click on it, you would put the script I wrote above (or one like it) in the stack script. Buttons that have scripts will fire the scripts you wrote, and buttons that have no script will tell you their names.
I hope that clarifies it for you.

Re: Collecting button names
If you never have a mouseDown handler in any button, then, unless I misunderstand what you are after, in the stack script:
If you do in fact have mouseDown handlers in certain buttons, you can kludge. As an example:
You could also use "mouseStillDown", and likely others...
Craig
Code: Select all
global buttonList
on mouseDown
put the short name of the target & return after buttonList
end mouseDown
Code: Select all
global buttonList
on mouseWithin
if the mouse is down then put the short name of the target & return after buttonList
end mouseWithin
Craig
Re: Collecting button names
Probably the easiest way is to put the logging handlers into a frontscript that traps mouseUp, logs it, and then passes the mouseUp so the rest of the controls will receive the message. When it's no longer needed, omit inserting the script into front.
This is a good example of when to use "open file for append" when you want to start logging. That way you can do everything in your original script with one line after you've opened the file:
This is a good example of when to use "open file for append" when you want to start logging. That way you can do everything in your original script with one line after you've opened the file:
Code: Select all
write the short name of the target & cr to file <path/to /file>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Collecting button names
Hi Linda,
as I wrote in another thread, you can have this much, much, much, much shorter!
Yes, much shorter!
Best
Klaus
as I wrote in another thread, you can have this much, much, much, much shorter!

Code: Select all
on closeCard
put specialFolderPath("desktop") & "/CardHistory.txt" into tFile
put the short name of this card & CR AFTER url("file:" & tFile)
end closeCard

Best
Klaus
Re: Collecting button names
Jacque.
Perfect time to use the frontscript.
Craig
Perfect time to use the frontscript.
Craig