4 Replies Latest reply on Jun 18, 2012 11:22 AM by Im out of ideas

    Asking for user input in the middle of a function

    Im out of ideas

      Here's my issue.

       

      I need to launch and input window in the middle of a function for user input.  Before I can continue through the function I need a response back from the user first.  Psuedo code below:

       

       

      function
      {
           function begins
      
           pop up window is launched to ask for user input
      
           function continues after users submits input
      
           user input from pop up window is used in function return value
      }
      

       

       

      Let me know if you need more clarification but this is essentially what I'm attempting to do.

        • 1. Re: Asking for user input in the middle of a function
          tinylion_uk Level 2

          You will need to use a pop up alert set to modal. With a function attached that wait for the alert to be filled and exited

           

           

           

          To follow your code example

           

           

           

          Sorry to be brief but im just about to fall into bed after an 16 h our day J

           

           

           

          Feel free to contact me off forum if you would like some help

           

           

           

          Cheers

           

          glenn

           

           

           

          function

           

          {

           

          function begins

           

          call Alert:

           

          - with modal set to true

           

          - with a return event listener set to call Result_function once the alert window is closed

           

           

           

                .. .. .. All other action now stops while the alert window is displayed

           

          }

           

           

           

          public var userResult;

           

           

           

          function Result_function

           

          {

           

                      Get the user input from the returned event

           

                      Validate the user input

           

                  function continues after users submits input

                  user input is saved in a public variable so you can use it somewhere else

                  or you just do what you need to do with the user input here

           

           

          • 2. Re: Asking for user input in the middle of a function
            Im out of ideas Level 1

            This example would use another function to continue the code progression.  I'm looking to stop the code progression within the same function.  I'm thinking my only option to accomplish this would be to enter a loop and wait for the the window to close before setting the loop condition to false and continuing the code.  for example

             

            function
            {
                 function begins

                 pop up window is launched to ask for user input

                      do while loop initiated and loops until window closes and loop condition is set to false (probably a global variable that is set to false by the window close event)


                 function continues after users submits input

                 user input from pop up window is used in function return value
            }

             

             

            Anyone else encountered this type of workflow and came up with an answer?

            • 3. Re: Asking for user input in the middle of a function
              tinylion_uk Level 2

              The way actionScript works it isn’t really designed to work that way

               

               

               

              Is there any reason why you have to only use one function as you have written

               

               

               

              I think you really do need to split up your code into sections that a, set up the pop-up with  event listeners waiting for the input to be completed, trigger the pop up with user input, then have a handler function that then interprets the results of the user action.

               

               

               

              Trying to force the system into a closed loop while waiting will be a bad idea.

               

               

               

              By using a pop-up or an alert window that is set to be modal, you are effectively stopping your application doing anything else until the user input has been completed, but still not locking the app into a closed loop. Imagine what would happen if you did put the system into a closed loop, the mouse movement wouldn’t be updated, the screen wouldn’t refresh and the system wouldn’t be able to handle your user input. the reason for using async model is you are able to let the system still do all its background task (move the mouse, give inputs focus, keep the screen drawn etc) but still tell a part of your app to ‘wait for input’ before carrying on it execution of your logic

               

               

               

              Do you come from another programming language? Maybe one that uses less of an OOP approach? I only ask, as the method you are describing is much more like how I had to program when  I worked on computers years ago as an assembly programmer.

               

              In actionscript and most other modern languages and Oss you don’t have total control of the system and cant lock it into an action as you describe.

               

              You need to have an asynchronous approach to situations like you describe and let the system run in the back ground while you are waiting for input (or date from a server for that matter)

               

               

               

              Please excuse me if I am telling you things you already know.

               

               

               

              What exactly is your use case for this? Maybe if we knew exactly what you are working on I might be able to offer a solution that would make sense for your particular situation.

               

               

               

              Hope all is going well and please feel free to contact me if you are stuck

               

               

               

               

              • 4. Re: Asking for user input in the middle of a function
                Im out of ideas Level 1

                agreed...i've re-written it using a proper event listener model which is my usual approach but the situation I was dealing with was unique.

                 

                the problem I had was I was reading in several files that the user can drag/drop into the application.  I wanted a clean way to get input on each file one at a time without writing a lot of dynamic code.  Essentially the user could drop, for example, 5 files.  I would need to create 5 pop ups to gather information about each file.  Creating a system to manage those pop ups and keep track of what info was tied to which file is something I wanted a clean procedural approach to.