Works sometimes -- but not other times

Peter M. Brigham pmbrig at gmail.com
Sun Jun 24 09:31:38 EDT 2012


On Jun 23, 2012, at 10:28 AM, Mark Rauterkus wrote:

> Hi,
> 
> Follow up. Some triggering issues / observations:
> 
> The handler,
>     on textChange
> 
> 
> does NOT seem to work if a script puts content into a field. When a
> user types into the fields, the messages gets passed well and all is
> fine with my scripts. I've gotten away from the "on idle" to look for
> changes in the fields. So, I'm now just doing on keyDown handler with
> the original input field.
> 
> on keyDown var, temp,  tWordCount, tNumberOfWords

No. Again, you aren't understanding how system messages work. When the user presses a key and the insertion point is in a field, a "keydown x" message is sent to the field. The one parameter that is sent with the message is the key that was pressed (eg, "x"). If there is no "on keydown" handler in the field, the message is sent up the message path and if there are no "on keydown" handlers further up the message path then it finally reaches the engine, which then allows "x" to be placed in the field. When you construct an "on keydown" handler as above, with 4 parameters, then when the message is received by the field, the one parameter that is passed as part of the message will be placed into your first parameter ("var"), and the other  three will be left empty.

It's as though you were told to expect one guest in a hotel but you prepared 4 rooms. The dictionary tells you what and how many parameters are sent along with what message. You have no control over this -- you have to pay attention to what parameters will be arriving and then handle them accordingly. Which may mean ignoring them entirely. For instance, look at the mouseup message, which is accompanied by one parameter, the mouseButtonNbr (1 = left, 2 = middle, 3 = right)

So you could do this:

on mouseup tBtn
   hide me
end mouseup

if you want to hide the button (or field, or image...) with any mouseclick, no matter what. In this case, tBtn will contain 1, 2, or 3, but you are not using it. So you could just as well do:

on mouseup
   hide me
end mouseup

and not bother to store the parameter in a variable at all, since you don't intend to use it.

Think of the parameters of a system message handler ("on mouseup tBtnNbr" or "on movestack newStackH, newStackV") as initially empty baskets that are filled sequentially with packages that accompany the message. You can put out fewer baskets or none at all if you don't plan to use some parameters, but there's no point it putting out 4 baskets when you know that you will only be receiving one package -- which will end up in the first basket, if you've put out too many.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig







More information about the use-livecode mailing list