|
Article
|
Difficulty
Rating
|
2
|
The
Basics: Understanding
stacks, subStacks and
mainStacks
|
|
A
window in MetaCard is
called a stack. Each
stack can contain any
number of screens, known
as cards. Cards contain
objects such as buttons,
text fields, images,
etc. By changing the
card currently being
displayed in a stack,
you change the entire
contents of the screen
being displayed in that
stack
(window).
Stacks
have a number of
properties to control
how they are displayed.
These include basics
such as width, location
and height. There are
also commands to control
what mode stacks are
opened in, i.e. whether
they are displayed as
palettes, normal
(toplevel) windows or
dialog boxes.
Not
all stacks are created
equal. There are two
types: the
mainStack and the
subStack. The
analogy is simple. A
mainStack is stored in a
file. SubStacks are
stored in mainStacks.
When you open a MetaCard
"document" on disk, the
mainStack will be
displayed. Scripts in
the mainStack can then
open any subStack in
that file. SubStacks are
used to implement any
other window in the
application you are
creating, for example
dialog boxes, menus, or
other program
screens.
Lets
walk through creating a
new mainStack, and then
the process of attaching
a subStack to it. Open
MetaCard, and create a
stack by choosing "New
stack" from the file
menu. A new stack will
appear, called something
like "Stack
00000000". The stack
properties palette for
that stack is
automatically opened
when you create a new
stack, so use it to
rename the stack so that
we can refer to it
easily again.
Now
choose Save from the
file menu. You will be
presented with a
standard Save As dialog
box, which allows you to
give the stack a file
name and save it on
disk. Type in "My
program.mc" and press
the Save
button.
Now,
create a new stack. You
could just save this
stack into another file
as another mainStack by
choosing Save from the
File menu again.
However, this time, lets
save it into the same
file as the mainStack
"My stack" we just
created.
|
Tip:In
case you're interested,
the number given to a
stack as part of its
title when you first
create it is the number
of seconds that have
elapsed since Thursday,
1st January, 1970. If
you choose "Message box"
from the Tools menu and
type in:
convert (word 2 of the short name of this stack) to long time; put it
you'll
get the time the stack
was created. This system
ensures that each stack
created will start out
with unique name.
Because the name is the
only way to refer to a
stack in a script, it is
a good habbit to make
sure that whatever you
name a stack is
different from *all*
other MetaCard stacks
stored anywhere on your
computer.
Note
that the semi-colon in
that example denotes a
new line. It can be used
to put multiple commands
or even repeat loops in
the message box. Simply
use a semi-colon to
separate
lines.
|
Use
the stack properties
palette that is
currently on screen to
name this stack "My
subStack". (If that
palette has dissappeared
for any reason, just
choose "Stack
properties" from the
Edit menu to get it
back). Click the
Properties tab. Click
the mainStack button.
Choose "My stack" from
the menu in the
mainStack dialog that is
now on screen. Press OK,
and then choose Save
from the file menu. This
time, you won't be
presented with a dialog
box asking you where you
want to save the stack.
Thats because it is now
part of the mainStack
"My stack" and will be
saved automatically into
the same file you saved
"My stack"
into.
Whats
special about a
mainStack? Whenever you
open a MetaCard document
(e.g. from the desktop
or using the MetaCard
File menu) it will open
the mainStack from
inside that file and
display it on screen.
None of the other stacks
in the file will be
displayed, though they
are all loaded into
memory. If you want to
go to other stacks each
time you load a
particular file, you'll
need to add a script to
do that. This makes a
mainStack the ideal
candidate for a splash
screen or welcome
screen.
Note
that whenever you save
any stack, all
the other stacks in that
file will be saved too.
So, when MetaCard tells
you its saving stack
someName as a subStack
of stack anotherName,
what it really means is
that its saving stack
someName, anotherName
and every other
stack in the file. There
is no way to perform a
Save on an individual
subStack.
|
Important
Note: Beware that
you can't alter which
stack in a file is the
mainStack. Once you have
created a mainStack,
your stuck with it.
Whilst any other stacks
can be called up or
ignored as required,
your mainStack will
always open when the
file is loaded. Deleting
it will delete all
subStacks in the same
file. Short of saving
each subStack out into
an individual file, and
reconstucting them in a
different order, you are
stuck with whatever
mainStack you start out
with.
|
Navigating around
stacks
As
already mentioned above,
stacks can be opened as
palettes and dialogs, as
well as normal windows.
To get to a stack, just
type
open
stack,
followed by the name of
the stack:
open stack "My substack"
How
do you open a stack as a
dialog box then? Instead
of using the
open
stack
command, you use a
command to specify that
the stack is opened
as a dialog box.
This is known as a
stack's
mode.
Typing:
modal "My substack"
in
the message box, which
would cause "My
substack" to opens in
dialog mode. Also useful
are:
|
palette "My substack" -- to open in palette mode
modeless "My substack" -- to open a window in a non-blocking but
-- non-editable mode for presenting information
toplevel "My substack" -- to re-open "my substack" in normal window mode
"Toplevel"
is the term given to
stacks opened in the
normal mode. Its usually
the same as
saying:
open stack "My substack"
The
toplevel
version of that command
will cause a stack that
is already open in
another mode (e.g as a
dialog or palette) to be
reopened as a normal
stack.
|
Creating
and navigating between
cards
Whenever
you create a stack, it
gets created with a
single card. The card is
the contents area inside
the window frame, onto
which you draw the
actual objects that make
up your application or
presentation.
So
far, we've talked about
creating separate stacks
and navigating between
them. Now lets suppose
you want to display
similar information and
navigate between it
inside the same stack.
Examples include
presentations, slide
shows, multiple panels
in a preferences dialog,
topics in a reference or
training guide, etc.,
etc. An easy way to do
this is to create more
cards in the
stack.
Draw
out a couple of objects
(using the Tools Palette
in the Tools menu), then
choose Create Card from
the Edit menu. The area
inside the stack will
empty, as the new card
does not contain any
objects. Draw out some
objects on this card.
Now choose Navigator
from the Tools menu. Use
the arrows to go forward
and backwards between
the two cards you
created. Create a button
and put the following
script into
it:
on mouseUp
visual effect dissolve
go next card
end mouseUp
Choose
the Browse tool to
switch from editing mode
to run time mode. Click
the button you just
created. You should
change card with a
dissolve effect. See our
article on
Groups
and
Backgrounds
for information on
creating objects that
appear on multiple
cards.
So
what if you want to go
to another card in
another
stack?
go card 3 of stack "my substack"
We
recommend you give cards
names to make them
easier to remember.
Choose Card Properties
from the Edit menu, and
name each card you
create in the same way
you name a
stack.
|
If
you want to go to a card
in another stack, whilst
opening that stack in a
different mode (e.g. go
card 5 of a stack opened
as a
palette):
go card 5 of stack "example stack" as palette
Finally,
if you want to go to
another card in a stack
but use the same window
frame as the stack you
are in:
go card 3 of stack "another stack" in the window of this stack
The
two stacks must be the
same width and height.
The user will not know
that you have changed
stack - as the new card
will appear in the same
window.
|
Tip:There
is an alternative way of
specifying the mode
(dialog
box/palette/etc.) that a
MetaCard stack is opened
in. Its called the
"style" property. This
property *over-rides*
any commands you use to
force a stack to open in
a particular mode. For
example:
set the style of stack "my stack" to palette
will
cause "my stack" to
always open as a
palette, even if you
specify:
toplevel "my stack"
This
is occasionally useful,
for example if you want
a mainStack to be opened
as a modal dialog box,
you'll need to set the
style property (the
mainStack will otherwise
be loaded by MetaCard as
toplevel).
|
Let's
step back and take a
look at the structure of
a typical MetaCard
program.
|
![](class2_fichiers/stack%2520hierarchy.gif)
You
can't edit a stack
opened in any mode other
than toplevel. However,
there will be many
applications where you
want to create palettes
or dialog boxes, and
want to tweak
them.
Its
easy to use the message
box to change the mode,
first by opening as a
modal to preview, then
as a toplevel to edit,
then as a modal again.
However, you may find
this process
inconvenient, because it
causes the stack's
scripts to operate every
time you do it. For
example, you may have
scripts that move run
every time a card is
opened, and you don't
want these to operate
again. Type:
lock messages; toplevel "My stack"
in
the message
box.
Finally,
you can change the
appearance of any stack
without changing its
mode. All stacks ,no
matter what mode the are
opened, in have a
decorations
property. This can be
used to override the
default decorations that
a stack displays (which
are determined by what
mode the stack was
opened in). Decorations
include the close box,
resize boxes, etc. Note
that setting the
decorations is the only
way to create a
completely borderless
stack, as there are no
modes to open stacks
without a border. To
make "My stack" a
borderless
window:
set the decorations of stack "My stack" to empty
This
will work regardless of
whether the stack is
opened as a palette,
toplevel, dialog,
etc.
|
Tip:If
you don't know the name
of a particular stack
that you want to edit,
simply bring the stack
into a position on
screen where it is
visible then move the
mouse over it then
type:
toplevel the mouseStack
into
the message box. If you
are still having
difficulties, move the
mouse back over the
stack and
type:
set the cantModify of the mouseStack to false
If
you still can't edit the
stack, the style must be
set.
set the style of the mouseStack to "default"
You'll
find that this will let
you edit even the most
stubborn
stacks.
|
|
Did you find this article useful?
Have any ideas for future topics?
Email
Us!
|
|