Getting the 'ClickWord'
Mac OS 9 Mac OS X Windows Windows

Normally you can use the clickText to retrieve the word that a user clicked on in a chunk of text. However, because of the way that all of the 'click___' functions operate, when clicking on decimal numbers like 12.34, the clickText returns either "12", "." or "34", which is not very helpful if you need the complete number.

Now a manual solution to this would be set the textStyle of those numbers in the field to "link" and then do this:

set the underlinelinks to false
set the linkcolor to 0,0,0
set the linkvisitedcolor to 0,0,0
set the linkhilitecolor to 0,0,0
to make the numbers look like any other text. However this affects the way any other "link" text is seen in your stack, since these properties are global.

So what can be done?

Well, you can use this handy script to retrieve the word that was clicked on, which will return the numbers as a single word:

-- Field script
on mouseUp
  put clickWord() into tWord
end mouseUp

function clickWord
  return word (the number of words of (char 1 to (word 2 of the clickCharChunk) of me)) of me
end clickWord
If you want to factor this function out (perhaps to put into a card or stack script), you'll need to make it a bit longer and add a parameter, but it uses the same principle:
-- card script
on mouseUp
  put clickWord(long id of the target) into tWord
end mouseUp

function clickWord pField
  do "put word (the number of words of (char 1 to (word 2 of the clickCharChunk) of" && \
      pField & ")) of" && pField && "into tRetVal"
  return tRetVal
end clickWord
Note that this will retrieve true words, so if there is any trailing punctuation, this is returned as well (for example if you had the phrase "I am here, you are there." and clicked on the word "here", you'd get back "here,"; similarly if you clicked on "there", you'd get back "there.".

Posted on 1/6/2005 by Klaus Major to the Use Revolution list
Modified and expanded for posting by Ken Ray on 2/10/2006