views:

95

answers:

4

In flex component life cycle, after we make some change in a components property, invalidation methods schedules a call to methods like commitProperties, updateDisplayList, etc for some later time. I need to call the updateDisplayList instantaneously. Is there some direct way to do this. Currently, both the labels are changed simultaneously after completion of the loop. Instead I need it to work like this, to first render the updated 'myButton1' label then enter the loop and then update myButton2's label. I know, it is elastic race track issue, but isn't there some way to achieve this ?

myButton1.label = 'New Label1' ;
// Some logic to forcibly make the screen reflect it

for (var i:int = 0; i < 500 ; i ++){
//a dummy loop

}

myButton2.label = 'New Label2' ;
+2  A: 

You can use myButton1.validateNow() but it's use is discouraged, for you may end up having the same component update itself multiple times on the same frame.

sharvey
+2  A: 

Use validateNow() . But, I would use it sparingly. using invalidateDisplayList() will force updateDisplayList() to run on the next renderer event.

A render event happens on each frame. 24 frames happen each second by default for Flex. Are you sure need to change these values quicker?

www.Flextras.com
Thanks for the help www.Flextras.com. I wonder if increasing the frame rate should be a good optoin. How will it affect overall, specially the elastic race track ?
Ashine
It is something I would experiment with before changing it in a production app. Some people have improved performance by changing the frame rate; others have not been so lucky.
www.Flextras.com
+1  A: 

I would set the label for myButton1, then put the remaining code into a separate method and call that method using callLater:

private function foo():void {
    myButton1.label = 'New Label1';
    this.callLater(bar);
}

private function bar():void {
    for (var i:int = 0; i < 500 ; i ++){ //a dummy loop
    }
    myButton2.label = 'New Label2';
}

This way myButton1 will update to show the new label before going into your loop since callLater doesn't call bar until after the event queue is cleared, giving myButton1 a chance to update.

Wade Mueller
Thank you so much Wade.
Ashine
A: 

invalidateDisplayList() or valdiateNow() will do it for you however excess of using these will end up memory leaks.

anand