Scripting a Button
Check the number of fields and buttons in your project by looking
at Card Info.. and Bkgnd Info... under the Edit menu of the menubar. When
you make a new card you keep the same background and the background fields
and background buttons, however, card objects and pictures are not copied
to the new card.
Background fields can have different text for each card of a particular background in the project. This
is very useful where you need the same design for each card but different
words, for instance a book of songs or poems
We have discovered how to script buttons to hide and show fields. Button
scripts can also change the name the button shows as well.
Make a new button named Show.
Open the Message Box (Command M) and type set the name of bg btn "show"
to "hide"
(bg btn is short for background button)
The ability to change the name of a button can be part of the hide and show
script. Use Option Command Click on the button to access the script. Type
in the following script.
Now the button name alternates between Hide Something and Show Something
as we click it. By adding the scripts that were used to hide and show fields
we can make a button that has a dual purpose. When it is named Hide it will
hide a number of fields and reset its name to Show. The next time it is
clicked it will reset its name to Hide and show all the fields. It looks
complicated but it is so useful that it is worth keeping a sample of it
in a button library so it can be put to use when needed.
Script for dual purpose Hide/Show button
This script is an example of if...then...else construction. If ... then
and if ... then ... else help to make the program responsive to the user,
so they are used in a lot of different places.
Another way of hiding and showing fields and buttons is to use a property
they have called visible. Try these out in the Message Box.
If the visible of a field is true then the not visible of
the field would be false and vice versa. Hide field 3 and type put the
visible of field 3 in the Message Box and press return. Now try this.
Press return a few times to see the effect. Now we can adapt our Hide/Show
script.
The Menubar property visible can also be set and assertained. Type set
the visible of menubar to false in the Message Box. Then type put
the visible of menubar.
You can do similar things with other objects such as graphics. Make a button
with the following script and try it out on a card with a background graphic.
or try this in the message box
Return to top of page
|