I am looking for a good approach to sometimes pause an action (calling a function / method) until the user confirms that he wants to perform a certain part of this action. I need to do this in an environment that does not stop the execution of the code (ActionScript in my case, but the approach for JavaScript should be identical).
To illustrate this, this is a mock action before entering a user prompt:
<preliminary-phase> // this contains data needed by all the following phases //
<mandatory-phase> // this will be always be executed //
<optional-phase> // this will always execute too, if in this form, but in some cases we need to ask the user if he wants to do it //
<ending-phase> // also mandatory //
I need to insert a conditional user prompt, "Do you want to do this part?" And do it <optional-phase>only if the user wants.
<preliminary-phase>
<mandatory-phase>
if(<user-confirmation-is-needed> and not <user-response-is-positive>){
<do-nothing>
}
else{
<optional-phase>
}
<ending-phase>
When trying to do this in ActionScript / JavaScript, I have something like this:
<preliminary-phase>
<mandatory-phase>
if(<user-confirmation-is-needed>){
askForConfirmation(callback = function(){
if(<user-response-is-positive>)
<optional-phase>
<ending-phase>
});
return;
}
<optional-phase>
<ending-phase>
<optional-phase> <ending-phase> . , , <preliminary-phase>, , .
, <optional-phase> <ending-phase> ( <preliminary-phase>), , , , , , .
, , ?
:
1. askForConfirmation . , , , ( return; ).