Lingo for checking mousewithin

Date:    Thu, 15 Dec 1994 13:46:22 EST
From:    John Dowdell <71333.42@COMPUSERVE.COM>
Subject: Re: Undoc'd Director Features....
Paul Farry writes on Dec 13 for implementation of "mouseEnter" style events. Examples are better seen than described, but I think the following should do the trick. (Note that this is advanced Lingo, folks... please don't jump directly from basic button work to this! ;)

You can send a message to a script just as you can to an object, through the syntax:

  <handlerName> (script "<name of cast script>")
 
An example would be "mouseUp (script 'myButton')". We can also go "mouseUp (script 23)", too. Note that a message sent to a script in this fashion must be able to be handled by that script or an error will result. This all builds off of the normal syntax for child objects, and does not rely on any backdoor Lingo.

The following is a script for a one-frame movie. There are many sprites on Stage, some of which are "hot", some of which are not. Each of these "hot" castmembers has handlers for "mouseEnter", "mouseWithin", and "mouseExit" events. The other castmembers on Stage do not have handlers for those events, and so those messages must only be sent to the "hot" castmembers.

  on startMovie
    global lastMC, hotCast
    set lastMC = -1
    --  These are the castmembers to which we can fire events:
    set hotCast = [the number of cast "red dot", the number of cast "howdy.aif", the number of cast et cetera et cetera et cetera...]
  end startMovie

  on exitFrame
    global lastMC, hotCast
    --  Capture the current mouseCast:
    set thisMC = the mouseCast

    --  If no change, and if we're over a hot
    --  castmember, then fire off "mouseWithin":
    if lastMC = thisMC then
      if getOne(hotCast, thisMC) then mouseWithin (script thisMC)
    end if

    --  If mouseCast has changed, and it's hot, then
    --  fire off "mouseExit" and "mouseEnter" events:
    if lastMC <> thisMC then
      if getOne(hotCast, lastMC) then mouseExit (script lastMC)
      if getOne(hotCast, thisMC) then mouseEnter (script thisMC)
      set lastMC = thisMC
    end if

    go the frame
  end exitFrame
The result will be that your "mouseWithin" handlers and such will be executed when you wish, without tons of rollover checks slowing things down... it usually requires just one function and two conditionals per frame, so it's lean.

This technique is not for everyone! It requires a good command of Lingo first. I believe it will be of benefit to people already using object-oriented scripting, but may be quite incomprehensible to those still trying to figure out why "put item 1 of list(a,b,c)" does not work... calls to tech support will not substitute for that experience! <wg>

But I hope this is of interest to you, Paul, and to others... definitely can be useful in "Help Bar"s and such.

Regards,

John Dowdell
Macromedia Tech Support


Date:    Thu, 15 Dec 1994 16:36:31 -0800
From:    Frank Leahy <fjl@NETCOM.COM>
Subject: Re: Undoc'd Director Features....
 
>You can send a message to a script just as you can to an object, through the
>syntax:
>
>  <handlerName> (script "<name of cast script>")
>
Did you notice that you can also pass parameters to the hander? The syntax is:
   send #mouseUp, script "foo", param1, param2, ...
You can then get those parameters using the paramCount and "the param of" functions (hmmm, I may have "the param of" wrong, that may be HyperCard's syntax, and as my machine is currently fixing someone's hard disk, I can't get the right syntax, but it's something like that). Unfortunately there's a bug in the send code such that the first parameter "param1" actually is passed as the second parameter, "param2" is the third, and so on. The first parameter is always 'script ""' -- I would guess that someone just didn't quite finish this code.

Because of this inconsistency, it's a little inconvenient to use, but could be useful.