Forcing Flex to update the screen?

前端 未结 6 1827
梦谈多话
梦谈多话 2021-01-05 05:28

This may be a bit of a beginners question, but I can\'t for the life of me figure it out.

I\'m using flex to develop a GUI for a large project, specifically a status

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 06:03

    Glenn,

    That is not at all how the threading in Flex works whatsoever. Like many UIs it has a message pump on the main UI thread (they do it in frames). When you call callLater() it places the passed in function pointer at the end of the message pump queue (on the next frame) and returns immediately. The function then gets called when the message pump has finished processing all of the messages prior (like mouse clicks).

    The issue is that as the property change causes UI events to be triggered, they then place their own messages on the pump which now comes after your method call that you placed there from callLater().

    Flex does have multiple threads but they are there for Adobe's own reasons and therefore are not user accessible. I don't know if there is a way to guarantee that a UI update will occur at a specific point, but an option is to call callLater a number of times until the operation occurs. Start off with a small number and increase until the number of iterations produces the result you want. Example:

    // Change this to a number that works... it will probably be over 1, depending on what you're doing.
    private const TOTAL_CALL_COUNT:int = 5;
    
    private var _timesCalled:int = 0;
    
    //----------------------------------------------------------------
    private function set Progress( progress:int ):void
    {
        progressBar.value = progress;
        DoNextFunction();
    }
    
    //----------------------------------------------------------------
    private function DoNextFunction():void
    {
        if( _timesCalled >= TOTAL_CALL_COUNT )
        {
            _timesCalled = 0;
            Function();
        }
        else
        {
            _timesCalled++;
            callLater( DoNextFunction );
        }
    }
    

提交回复
热议问题