How do I...?

Ask the User for Confirmation Before Exiting

In AutoPlay Media Studio, it is possible to stop closing your application based on user input, even after the close button has been pressed, or the Application.Exit action has been used.  This is useful if, for example, you are worried that the user will accidentally close your application, or if you want to allow the user to save their changes before they exit.

To accomplish this, you must include a function (QueryAllowProjectClose) in your Global Functions (Project > Global Functions) that returns true if the program should close, and false if it should not:

function QueryAllowProjectClose()  --this function will be called when the program is exiting
    confirmation = Dialog.Message("Are you sure?", "Are you sure that you want to exit?", MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    if confirmation == 6 then
        -- The yes button was pressed, allow program to close (return true)
       return true;
   else
       -- The yes button was NOT pressed, do NOT allow the program to close (Return false)
        return false;
    end
end

Note: This function is called internally by your application when it is told to exit.  If true is returned, your application will exit.  If false is returned, your program will not exit.

To use this function, you would use script similar to this:

if QueryAllowProjectClose() then
   Application.Exit();
end