Satimage Previous | Next
prepare
Home Documentation Smile Smile's objects Programming an object Writing an object's script prepare  
  • When Smile creates an object, it sends a prepare event to the object's script before bringing it in view. Smile creates an object when you open a document, or when you make a new one from scratch. For instance, when you double-click a SmileLab bundle, it opens as a graphic window in Smile: the script of the graphic window will receive prepare just before becoming visible. The same is true for text windows and for dialogs.

    You handle prepare with a handler such as:
    on prepare the_object
        -- do whatever is required to prepare the object
    end prepare
    where the_object is a reference to the owner of the script, the object which is being created. You will probably want to perform any required initialization in that handler.
  • In Smile, an invisible window does not have an index. When the prepare handler runs, its owner (if it is a window) is not yet visible, so window 1 is really the first visible window, not the window which is being created. For instance when you open a dialog with a text window as the front window, the text window is window 1 when the dialog's prepare runs - it will be window 2 just after.
  • Do not use the visible property in a prepare handler. If you want to test whether the prepare handler is being called by Smile in the file's opening phase or rather by another script, test whether the dialog window is or not window 1.
  • The prepare handler may itself - for instance to handle the case where some checking has failed - use the delete verb to delete the object which is being created: you can cancel the opening of a document in the prepare handler.

    Here is a prepare handler to have a Smile document (a text document, a dialog file or a SmileLab bundle) require a password to open.
    on prepare the_window
        if askpassword("Enter password:") is not ":-)" then
            FatalAlert("Access denied")
            delete the_window
            return
        end if
    end prepare
Copyright ©2008 Paris, Satimage