PDA

View Full Version : HOWTO: Prompt the User for Confirmation Before Exiting



Support
10-03-2002, 10:50 AM
<HTML><HEAD><TITLE>HOWTO: Prompt the User for Confirmation Before Exiting</TITLE></HEAD><BODY><h3>HOWTO: Prompt the User for Confirmation Before Exiting</h3><b>Document ID: IR04013</b><hr>The information in this article applies to:<ul><li>AutoPlay Media Studio 4.0</li></ul><hr><h3>SUMMARY</h3><p>This article describes how to prompt the user to confirm that they would like to exit your application.</p><h3>DISCUSSION</h3><p>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:</p><p>%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.</p><p>First go to <b>Project | Settings</b>, click the Actions tab and select the "On Close" event. You will be creating all of your actions in this location for this example.</p><p>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 <b>Dialog.MessageBox</b> 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:</p><pre><code>%Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)</code></pre><p>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 <b>IF</b> 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 <b>Variable.SetValue</b> action. Your action list should now look something like the following:</p><pre><code>%Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)<br>IF (%Result% = "NO")<br> %PreventApplicationClose% = "TRUE"<br>END IF</code></pre><p>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 <b>ELSE</b> clause to the condition and set the variable %PreventApplicationClose% to the value "FALSE", again using the <b>Variable.SetValue</b> action.</p><p>Your finished actions list will look something like the following:</p><pre><code>%Result% = Dialog.MessageBox("Title","Are you sure you would like to...",Yes|No, Question)<br>IF (%Result% = "NO")<br> %PreventApplicationClose% = "TRUE"<br>ELSE<br> %PreventApplicationClose% = "FALSE"<br>END IF</code></pre><p>KEYWORDS: prevent close, application close, %PreventApplicationClose%, confirm</p><hr><FONT SIZE=1>Last reviewed: October 4, 2002<br>Copyright 2002 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br></FONT></BODY></HTML>