HOWTO: Prompt the User for Confirmation Before Exiting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Support
    Forum Member
    • Jan 2000
    • 204

    HOWTO: Prompt the User for Confirmation Before Exiting

    HOWTO: Prompt the User for Confirmation Before Exiting

    HOWTO: Prompt the User for Confirmation Before Exiting

    Document ID: IR04013
    The information in this article applies to:
    • AutoPlay Media Studio 4.0

    SUMMARY

    This article describes how to prompt the user to confirm that they would like to exit your application.

    DISCUSSION

    In many cases AutoPlay Media Studio applications are used to present a large amount of information and even collect information from the user. In these situations, user error can result in closing the application accidentally, forcing them to start over from the beginning. In these cases, it's often useful to create your application in such a way that the user not be subjected to these accidental issues that may cause them frustration. This functionality can be attained by creating a series of actions in your application, but centers around the use of the built-in variable %PreventApplicationClose% which is defined as follows:

    %PreventApplicationClose% controls whether the AutoPlay application will proceed from the "On Close" event to the "On Destroy" event. Use this variable to conditionally "override" the user's ability to close your AutoPlay application. This variable is initialized to "FALSE" when the AutoPlay application starts. You can set it to "TRUE" to prevent the application from closing, and set it back to "FALSE" to allow the application to close again. If this variable holds "TRUE" at the end of the "On Close" event, the application will not close, and the "On Destroy" event (which normally follows immediately after the "On Close" event) will not happen. Any further attempts to close the application while the variable holds "TRUE" will fail. If the variable holds "FALSE" at the end of the "On Close" event, the "On Destroy" event will be triggered and the application will close.

    First go to Project | Settings, click the Actions tab and select the "On Close" event. You will be creating all of your actions in this location for this example.

    Your first task is to ask the user if they are sure they would like to exit the program. To accomplish this, you could use a Dialog.MessageBox action with the "Yes/No" dialog type. By default, the button value that the user clicked will be stored in the variable %Result%. Using this action you will know what button the user clicked by what value is returned in %Result%. The result will either be "Yes", meaning I'm sure I want to exit, or "No", meaning I don't want to close yet. Your action should look something like the following:

    %Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)

    Next you want to perform actions based on what the user selected on that message box. So if the user selected "No", you want to prevent the user from exiting the application. To do so, first create an IF control structure to see if the variable %Result% = "NO". If it does, set the built-in variable %PreventApplicationClose% to the value "TRUE". You can do this using a Variable.SetValue action. Your action list should now look something like the following:

    %Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)
    IF (%Result% = "NO")
    %PreventApplicationClose% = "TRUE"
    END IF

    The last step is to address the case where the user selected "Yes" on the message box, in which case, they are saying, yes, I'm sure I want to exit. To accomplish this you would add an ELSE clause to the condition and set the variable %PreventApplicationClose% to the value "FALSE", again using the Variable.SetValue action.

    Your finished actions list will look something like the following:

    %Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)
    IF (%Result% = "NO")
    %PreventApplicationClose% = "TRUE"
    ELSE
    %PreventApplicationClose% = "FALSE"
    END IF

    KEYWORDS: prevent close, application close, %PreventApplicationClose%, confirm


    Last reviewed: October 4, 2002
    Copyright © 2002 Indigo Rose Corporation. All rights reserved.
Working...
X