suppressing HandlerNot Defined alert


[ Zettels Traum ] [ search / suche ]


Here's a neat trick I stumbled upon by reading, of all things, the online docs!

Make a parent script, called "Crap"
----------
-- Crap

on new me
  return me
end

on doThing1 me
  put "I am thing 1"
end
----------

Now set gCrap to new(script "Crap")

At this point, you can say:

doThing1(gCrap)
--"I am thing 1"

but if you say:

doThing2(gCrap)

you'll get a "handler not defined" alert dialog.


So what to do if you need to call a handler you're not sure is there to
recieve the message? (this occurs when creating/simulating your own events
- it'd be nice to be able to propagate your own events, and have the events
just bounce off of scripts not equipped to process them, the way mouseDown
events bypass score scripts which have no mouseDown handlers).

You can use an interesting feature of the call keyword. The online docs say
you can send call a script instance, or a list of script instances for it
to process. When you send it a list of instances, it tries to message each
script, but won't put up an alert for failure. So, using our previous
example:

call(#doThing2, gCrap)

will still produce a "handler not defined" alert, while:

call(#doThing2, [gCrap])

will not! This is similar in concept to the way sendAllSprites events
bounce off of sprites without handlers to use the broadcast event.

Haven't tried making this work with movie scripts, though I'd imagine it's
possible that it's possible...

JD tried to pound something like this concept through my thick skull over a
year ago, but I'm afraid I didn't see the distinction between the operation
of "call" with a list of 1 instance vs. a bare instance.

Have fun!

David Cain

Clocks go slow in a place of work - minutes drag and the hours JERK!





Dazu:























D. Plänitz