If you need to close all substacks of a main window (stack) this is the code you need:

On closeStack
   put the substacks of this stack into temp
   repeat for each line tempSt in temp
      close stack tempSt
   end repeat
end closeStack

This tip is very useful when you hame many open window, this way you closing the main window, you close all others. The handler 'on closeStack' is sent to the current CARD when the STACK closes. Put this handler in the main CARD, not the main STACK. The main stack will receive this handler every time a sub stack is closed. That's not what you want.