How do I determine objects in a group?
Jeanne A. E. DeVoto
jeanne at runrev.com
Fri Feb 8 18:00:01 EST 2002
At 2:04 PM -0800 2/8/2002, Zac Elston wrote:
>The user can select only one circle from a group of circles. I use a
>backgroundcolor change to indicate selection. So basically I have to change
>a property of an object within a group while resetting the same property of
>all the other objects in that group.
>
> I can write a script for each circle
>
>On mouseup
>Put name into varX
>Set the backgroundcolor of graphic 1 to red
>Set the backgroundcolor of graphic 2 to gray
>Set the backgroundcolor of graphic 3 to gray
>End mouseup
>And change the red to match the graphic being pressed.
>
>But that seems tedious.
It is. Here you'll want to put the script in question higher in the message
hierarchy. The right way to do this, I think, is to put it into the group
script:
on mouseUp
if word 2 of the name of the target is not "graphic" then pass mouseUp
-- do your stuff here
end mouseUp
This gives you just one handler for the entire group. Now, since the user
can highlight only one circle, one way to handle keeping track of this
would be to set a custom property (let's call it "redCircle") for the group
to hold the currently-highlited circle. Then when you switch to another
circle, you only have to change the previously-highlited one, instead of
changing them all:
on mouseUp
if word 1 of the name of the target is not "graphic" then pass mouseUp
if the redCircle of me is not empty
then set the backgroundColor of graphic ID (the redCircle of me) to gray
set the backgroundColor of the target to red
set the redCircle of me to the short ID of the target
end mouseUp
--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
http://www.runrev.com/
Runtime Revolution Limited - Power to the Developer!
More information about the use-livecode
mailing list