mouseDown/Up - no actions when not on buttons

J. Landman Gay jacque at hyperactivesw.com
Tue Feb 8 23:08:53 EST 2005


On 2/8/05 4:54 PM, Silver, Jason wrote:

> case navUp
>   -- Determine which text field the user is currently in
>   put the short name of the selectedField into activeField
>   if activeField = "User ID" then
>     focus on field "Password"
>   else -- The user must be in the password field
>     focus on field "User ID"
>   end if
>   break
> 
> This works all well and good, except when pressing on an area that's not
> a button (in my stack, the purpleish area).  The cursor then disappears
> from either the User ID or Password fields, and then when pressing Up or
> Down, the following error occurs (because the focus is not in a field):
> 
> Type: Chunk: no target found
> Object: Login Screen
> Line: put the short name of the selectedField into activeField

That's because when you click on the card, no field is in focus. The 
"selectedfield" will be empty, and you can't get the short name of empty.

Instead of trying to get the name for all cases, change the syntax to:

case navUp
     -- Determine which text field the user was in
     if the selectedField contains "User ID" then -- change this
       focus on field "Password"
     else -- Currently in password field
       focus on field "User ID"
     end if
     break

By using "contains" instead of "equals", you can work with an empty 
case. Since it is never used more than once, you can also eliminate the 
line that puts the selectedfield into the variable; just compare it 
directly.

I took a quick look at your script, and noticed you have an "exit" 
statement as the last line of the handler. No need -- all messages 
automatically stop at the end of the handler, unless they are expressly 
passed. The buttonPress message will never go any farther.

You don't need "send to" in the button scripts -- all messages are 
automatically sent to the card if the button itself doesn't handle them. 
Use:

on mouseup
  buttonPress "selectKey"
end mouseup

But even better, since you have elegantly named your buttons for the 
messages they send (which is good,) you could put this same script in 
all of them:

on mouseUp
  buttonPress (the short name of me)
end mouseUp

And if you wanted to get really fancy, don't put any scripts in those 
buttons at all. Leave them completely empty. Instead, use a single card 
script:

on mouseup
  get the name of the target
  if it contains "button"
  then buttonPress (the short name of the target)
end mouseUp

This last approach will work even if you add future buttons that aren't 
supposed to use the "buttonpress" message. If you give those future 
buttons their own "mouseup" handler, then the "mouseup" message they 
catch will never reach the one that is living in the card.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


More information about the Use-livecode mailing list