mouseUp handler:
-- sprite script for some field called "wotsit" on mouseUp -- find out the number of the word that was clicked put the mouseWord into wordNum -- discover what that word actually is put word wordNum of field "wotsit" into clickedWord -- act appropriately if clickedWord = "blah" then go to "info about blah" end mouseUp
As well as the mouseWord, Director provides some other
functions to determine what part of a field the mouse is over:
the mouseChar the mouseItem the mouseLine
All of these return the number of their respective chunk in the field
that the mouse is over (if it is over a field). If you wish to discover
what that chunk contains, you have to get it from the field much as the
mouseUp handler above does. (It is quicker not to, however.
Putting the actual words in the script will make things clearer, but for
optimum performance you may want to use the numbers directly.)
These functions need not be used in response to a click. You may, for example, want to hilite the item under the mouse as the user moves it around by putting something like this in your idle script:
-- very basic handler to hilite any item under the mouse -- NB: a useable version would probably also unhilite items -- when the mouse leaves the field on idle put the mouseItem into theItem put the mouseCast into theField if theItem>0 and theField>0 then hilite item theItem of field theField end idle
Note that if the mouse is not over a text field, or is over some inappropriate
part of it like the border or scroll bars these functions return
-1 (that's what the if statement is for in the
above handler), but if the mouse is over empty space beyond the last chunk
in the field, the functions return the number of the last chunk.