Tip: 创建UI需考虑中间状态 Do not ignore UI intermediate state while creating custom components

!When creating a custom UI component, one should remember that the UI component does need time (sometimes very long time) to complete the construction. I refer the state between the constructor is called and the UI is fully created completely as the intermediate state, i.e., a transient state.

You should take extra caution on intermediate state when you create complex or composite UI components. One reason is that many functions do not work as expected during this state. For example, ListBase.listItems() should return all the renders, but it might return zero or few of the renders in this state.

Recently, I encountered a very strange problem with a custom Tree. This custom tree is able to automatically resize so the ugly scroll bar will never show up. The problem is that sometimes this tree shows up in the UI but many times it does not! The reason? The auto resize function relies on transient internal variables that change during the intermediate state. The solution? disable the auto resize function until the tree creation is done. You can always listen to creationComplete event to detect when the UI is fully constructed. I find that using visible property is easier:

protected function performAutoResize(event:Event = null):void {
    // Bugfix: in the intermediate state - auto resize incremented by -20 till 0.
    if(! visible) { // if not visble, do nothing.        
       return;
    }
    ... // the resize magic goes here
}