Flash UI blocked during flex rpc.soap.Operation :: send

I have a Flash interface that periodically calls the server to get updated information. The call uses the flex class sdk rpc.soap.Operation. It looks something like this:

var wsOperation:Operation = Operation(webService.getOperation(SomeOperation));              
wsOperation.addEventListener("fault", wsError);
wsOperation.addEventListener("result", wsResult);           
wsOperation.send(...some params);

This call retrieves some data from an SQL database. I programmed the call right before sending it to the beginning of the wsResult function in ~ 4 seconds. During this time, my user interface is not updated. He is frozen / not responding.

Now I know that Flash is single-threaded / asynchronous, so I'm not sure why this is happening. I see that the send (..) function returns an AsyncToken, which I do not use. Could this have anything to do with this?

Any other ideas as to why this is happening are appreciated. Thank.


I still have not found an acceptable solution. It seems ridiculous that I would have to use Pseudo thread to get flash to update the user interface during a 4 second call. I am wondering, maybe parsing a syntax response can take a lot of time. If a lot of processing is required, will the time delay update the UI indefinitely?

+3
source share
1 answer

You will get the user interface freezing in Flash because it is single-threaded. However, you can do pseudo-threading with something like this:

package
{
 import flash.display.DisplayObjectContainer;
 import flash.events.Event;
 import flash.events.EventDispatcher;
 import flash.events.KeyboardEvent;
 import flash.events.MouseEvent;
 import flash.utils.getTimer;
 import mx.core.UIComponent;
 import mx.managers.ISystemManager;

 public class PseudoThread extends EventDispatcher
 {
     public function PseudoThread(sm:ISystemManager, threadFunction:Function, threadObject:Object)
     {
         fn = threadFunction;
         obj = threadObject;

         // add high priority listener for ENTER_FRAME
         sm.stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler, false, 100);
         sm.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
         sm.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

         thread = new UIComponent();
         sm.addChild(thread);
         thread.addEventListener(Event.RENDER, renderHandler);
     }

     // number of milliseconds we think it takes to render the screen
     public var RENDER_DEDUCTION:int = 10;

     private var fn:Function;
     private var obj:Object;
     private var thread:UIComponent;
     private var start:Number;
     private var due:Number;

     private var mouseEvent:Boolean;
     private var keyEvent:Boolean;

     private function enterFrameHandler(event:Event):void
     {
        start = getTimer();
        var fr:Number = Math.floor(1000 / thread.systemManager.stage.frameRate);
        due = start + fr;

        thread.systemManager.stage.invalidate();
        thread.graphics.clear();
        thread.graphics.moveTo(0, 0);
        thread.graphics.lineTo(0, 0);   
     }

     private function renderHandler(event:Event):void
     {
         if (mouseEvent || keyEvent)
             due -= RENDER_DEDUCTION;

         while (getTimer() < due)
         {
            if (!fn(obj))
            {
                if (!thread.parent)
                    return;

                var sm:ISystemManager = thread.systemManager;
                sm.stage.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                sm.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
                sm.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
                sm.removeChild(thread);
                thread.removeEventListener(Event.RENDER, renderHandler);
                dispatchEvent(new Event("threadComplete"));
            }
         }

         mouseEvent = false;
         keyEvent = false;
     }

     private function mouseMoveHandler(event:Event):void
     {
        mouseEvent = true;
     }

     private function keyDownHandler(event:Event):void
     {
        keyEvent = true;
     }
 } 
}

. RENDER . ActionScript-, , . . http://blogs.adobe.com/aharui/2008/01/threads_in_actionscript_3.html

+3

Source: https://habr.com/ru/post/1733424/


All Articles