front script back script
Ken Ray
kray at sonsothunder.com
Fri Oct 8 14:21:03 EDT 2004
On 10/8/04 7:56 AM, "Thomas McGrath III" <3mcgrath at adelphia.net> wrote:
> Hello to all,
>
> Does anyone have an example stack of how and why to use a front/back
> script? I have read the docs and have never used them. I need to see a
> real reason and example on how they work and why they are useful.
Funny you mention that... I just responded to the Improve Rev list as
follows:
> It seems to me that Revolution and SuperCard are unique in the way they
> provide frontScript and backScript functionality to the message path.
I would agree, at least as it relates to frontScripts. Many other languages
don't even have a message passing hierarchy, so it's sometimes like
comparing apples and oranges.
However, my understanding is that in a truly object-oriented environment
(which neither Rev nor SC are), you can provide methods for the object class
as a whole so that objects of that class can all perform the same thing.
This may be more akin to what's been spoken about recently as "object
backscripts" (i.e. multiple objects sharing a named parent as it relates to
the message passing hierarchy), but I *do* know that I have found
frontScripts to be incredibly useful. Others may not have used them or found
a use for them, but here's what I've used them for:
1) Cross-Platform Font Management: I have a "preOpenCard" handler in my
frontscript that changes the textFont/size/style of every object on a card
to one that looks appropriate for the platform (I don't use profiles as you
can tell).
2) Centralized Menukey Handling: If I want a certain keystroke (say,
Command-C) to copy things before any field runs it's rawKeyDown or rawKeyUp
handler, this is a good way to do it.
3) Centralized Popup Menu Handling: If I have a common context popup menu
that I want to display on fields or objects of a certain type, it is far
easier to put the code to pop it up in a frontScript than rely on the object
passing the message to a parent/backscript/library.
4) Centralized Drag and Drop Handling: I've used it so that tabs in the text
that is being dropped in a field are replaced with space so that I don't get
inadvertent tabs in the field.
In all of the above cases, I can always pass the message on to the actual
target so that it can do *additional* things after the centralized stuff is
done - this is the benefit of frontscripts - if I were to implement it as a
library or backscript, each object would have to be coded to pass the
message, and then my centralized stuff would happen *after* the target,
instead of *before*.
Quite useful, IMHO.
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list