Custom Properties
Chipp Walters
chipp at chipp.com
Wed Apr 12 23:08:14 EDT 2006
J. Landman Gay wrote:
> Now I'm curious what's the advantage, if any, of using a setProp handler
> over a standard command handler? This isn't just to you, Devin, but to
> anyone who uses these regularly.
While this horse has been beaten down, I prefer setProp for custom
library and/or control handlers...though not in *every case*.
For instance, say I have an object called 'altSlider' which is actually
a group of controls, but for simplicity's sake, I'll call it an object.
Let's say the purpose of the object is to slide back and forth a door
(graphic) revealling and concealing some 'secret' buttons (which are not
part of the object). IOW, there's a simple button which when clicked,
slides a graphic which is part of the group to reveal or conceal the
controls.
Now, I could have as the script of the simple button:
on mouseUp
toggleRevealConceal
end mouseUp
where toggleRevealConceal would have to figure out what 'state' the
object is in: closed or open, then do the opposite. Furthermore, to
programatically slide open the object from somewhere else-- say on
openCard, then you'd have to
send "toggleRevealConceal" to grp "altSlider"
and still you wouldn't really know what state it was in (unless you used
globals or some nifty local programming), so if it was already open, it
would close it, etc..
By using customProps, this is all made a lot simpler.
The script of the button is simply:
on mouseUp
if the altState of me is "open" then
set the altState of me to "closed"
else
set the altState of me to "open"
end if
end mouseUp
and:
on openCard
set the altState of grp "altSlider" to "open"
end openCard
By having a setProp handler which manages all of this, it makes reading
and writing the code much simpler.
Furthermore, a correctly scripted object of this type, with the liberal
use of 'me', allows for multiple 'objects' on the same card/stack level.
So one could say:
set the altState of grp "altSlider1" to "open"
set the altState of grp "altSlider2" to "closed"
and everything would work as planned.
You could also set other properties of the slider like the altSlideTime,
or the altDirection as well.
best,
Chipp
More information about the use-livecode
mailing list