5 Replies Latest reply on Apr 2, 2009 8:46 PM by Lehaleha

    User initiated actions model and async calls. Again

      Hi guys,

      I'm new at AS/Flex, so maybe I just don't get a point. I will be happy if so. Feel free to say: "hey, you are stupid, do this in a such way: <bla-bla>" ;))

      But now I'm really confused. Here is the reason: I know that:

      1) AS/Flex is asynchronous, event-driven platform. It has no methods similar to "sleep(timeout)" and (as said everywhere across the web) it is bad idea try to emulate "sleep()" via loops or any other hacks. One should forget about "launch -> sleep-till-job-ready ->continue" model and just subscribe to COMPLETE event. Its OK.

      2) "User initiated action" security concept is also seems reasonable. Any action should be permitted by explicit 'click/press/drag" event. OK.

      But when you sum 1) and 2) you get into a big trouble. Even if you have a button "Do job and send result" - you will be unable to execute method from UIA-restricted API if you have any async processing in execution path. Because event is fired from another internal thread and there is no "user-initiated-action" in stack! But even "Loader.loadBytes" is async! I cannot load image during "doing job", however I always thought that it is a sort of basic operation in any RIA.

      Am I right, that the only way to avoid SecurityError is to have 2 buttons - "Do job" and "Send results"?

      If it is so, its bad... In my case it is absolutely meaningless for user. He/she already set all params, confimed changes and I even have nothing to show after "Doing job". Except maybe dummy message "John, and now you should press "Send" button"... :(

      Maybe there is some way to pass some sort of "permission ticket" via events?
      I lost two days, but still don't believe that such obvious task cannot be done with such powerfull product.
        • 1. Re: User initiated actions model and async calls. Again
          JeffryHouser Level 4

          I don't understand.

          If you want to show a pop-up to users before the action starts, show the pop-up when the user initiates the action and do the real action when the user interacts with the pop-up.

          If you want to prevent the user from interacting with the application while the job is going on. Disable the app in the "Start Action" method handler and re-enabled it in the "Result" method handler.

          If you have asyc processing as part of your action; do the processing you can up until the async part; then continue on the saync result handler method.
          • 2. Re: User initiated actions model and async calls. Again
            Richard_Abbott Level 3
            you are at liberty to pass whatever you like in a custom event, but I don't think you need that kind of capability.
            Surely the easiest way to do what you want is one of two choices:
            1) Let the user get on with other stuff while waiting for their process to complete, or
            2) Make it clear to them there's nothing they can sensibly be getting on with until it returns.
            Either way you need some kind of GUI item showing the current state of their operation. I am assuming that the processing takes long enough you have genuine concerns about this?
            Think of it like sending a post to this list - you can either get on with other stuff while you're waiting for someone to reply, or you can just sit looking at the screen!
            I would probably recommend you have your server-side code managing some aspects of this, so that if they get bored or go home overnight the whole invoked process is not lost. That is outside the scope of your Flex app but is part of your whole system. In that case think of it like email - you can close your computer down and when you next switch on you can find out who has replied.
            Hope that helps,
            • 3. Re: User initiated actions model and async calls. Again
              Lehaleha Level 1
              Hi guys,

              Thanks for the answers and sorry for my English. I'll try again to explain my problem.

              I don't want any pop-ups. All I want - one single button - "Do job". But the problem is that the job itself has URLLoader.load() method at the end and some asynchronous call in the middle.

              URLLoader.load() is restricted method, which may be called only when there is some user-initiated-action higher on stack. And the problem is that I cannot get this damn UIA on stack. Here is err... some sort of program flow diagram %) :

              do-the-job-click() -> SomeSyncAction() -> SomeAsyncActionStart() .... <here we lost our UIA permission> ... SomeAsyncMethodCompleteEventHandler() -> UploadResults()

              And - UploadResults() cannot call URLLoader.load(). Because it is not UIA for Flash. But async methods are all over AS3/Flex API! Each of them breaks calls chain and after each such call!
              • 4. Re: User initiated actions model and async calls. Again
                Level 7
                As far as I can tell, you're correct. My suggestion would be to allow
                continued user interaction while processing, and give some visual
                identifier that the data is being processed. Then, when the processing
                has finished, display a pop-up with the option to send or cancel.

                For more information about these security measures, as well as a list of
                the operations they apply to and the reasons, see:

                • 5. Re: User initiated actions model and async calls. Again
                  Lehaleha Level 1
                  Thanks to all for the answers.

                  I hope that Adobe developers read this forum and they will do something with this stuff. Some sort of signed swfs, permission tickets which can be passed across events chain or bound to some objects or anything else.

                  UIA restrictions are real pain. Yes, roar of displeased voices now almost gone - after swfUploader update, which was installed on each blog. And users accepted to use Flash UI to initiate actions (maybe with some hacks such as transparent buttons %)).

                  But the problem which I faced is more fundamental, IMHO of course. It prevents a lot of scenarios which are natural for RIA. And it restricts "fair players". I mean developers which wanna create AS3/Flex apps with rich flash UI and significant client-side data processing.

                  Best regards, Alex