Dumb Newbie Questions -- 3 of N
J. Landman Gay
jacque at hyperactivesw.com
Sat May 2 13:49:37 EDT 2009
Richmond Mathewson wrote:
> I set up a stack with a button "Holder" which contains 3 custom properties:
>
> dataDish
> custardPie
> sexyMessage
>
> containing, respectively, tab-delimited data, a number, and a string.
>
> All very straightforward . . .
>
> However, when I tried this:
>
> on mouseUp
> put the customProperties of btn "Holder" into fld "fPROPS"
> end mouseUp
>
> nothing happened, and, confusingly, I had to do this instead:
As was mentioned, sets of properties are stored as arrays. If you
inspect the array itself, you'll see your data.
Let's try something simple. Suppose you have a card with lots of buttons
that the user can move around; maybe your script uses the "grab" command
to let them drag the butons. Now you want a way to reset the card to its
native state that puts all the buttons back to their original positions.
Buttons have a "loc" property, but that only stores the current position
of the button at this moment, and the engine will update that value
every time the button moves. There isn't any native property that tells
you where the button started from, but we can make a custom property
that does that. We'll call it the "startLoc" and each moveable button
will need to have that property assigned to it. Before the user has a
chance to drag anything (maybe during development, or during
preopencard) you run a little handler that sets that property for each
button:
on setBtnLocs
repeat with x = 1 to the number of btns
set the startLoc of btn x to the loc of btn x
end repeat
end setBtnLocs
Now each button has a custom property called "startLoc", and the value
of the property for each button is it's current position.
Now you're ready to grab the buttons and move them all around till
nothing is in the right place any more. Then you can click a "Reset"
button which puts them all back with this simple script:
on mouseUp
repeat with x = 1 to the number of btns
set the loc of btn x to the startLoc of btn x
end repeat
end mouseUp
Your custom property "startLoc" acts just like any other property. The
only difference is that the engine doesn't create or update it, you do.
I can think of several other ways to store each button's start position,
but none of them are this simple, and none of them tie the correct value
to each button individually the way having a custom property does. The
startLoc of each button becomes an integral attribute of the button just
like its color or its name, and is the only way to accomplish this
example with any degree of efficiency.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list