Would this be a situation for a Front Script?
Dave Cragg
dcragg at lacscentre.co.uk
Mon Mar 13 16:22:00 EST 2006
On 13 Mar 2006, at 21:07, Garrett Hylltun wrote:
>
> I have about 200 objects on a card, and I want to have mouseEnter
> and mouseLeave handlers for all of them, but instead of writing
> code for each one, would it be better to just use a front script to
> intercept these events?
Instead of a front script, handlers in the card script would probably
be easier. This takes advantage of the Rev message hierarchy. If the
mouseEnter and mouseLeave messages aren't handled in the objects
themselves, the messages pass on to the card.
>
> All of them will do the same thing, which is change the color of
> the background of each object on enter and then change it back on
> leaving. I have the objects named individually like this "box1" all
> the way through "box200". So determining which object fired the
> event is not an issue.
Small suggestion, although perhaps not so important in this case.
When you have many items named basically the same but appended with a
number, I find it more useful to make the names into two words. For
example, "box 1", "box 2", "box 115", etc. Then it's easy to get the
numbered part by using "word 2 of the short name of whatever".
The handlers in this case might look like this:
## in card script
on mouseEnter
if word 1 of the short name of the target is "box" then
set the backcolor of the target to <color>
end if
end mouseEnter
on mouseLeave
if word 1 of the short name of the target is "box" then
set the backcolor of the target to <color>
end if
end mouseLeave
Cheers
Dave
More information about the use-livecode
mailing list