1 public function Application()
2 {
3 UIComponentGlobals.layoutManager = ILayoutManager(
4 Singleton.getInstance("mx.managers::ILayoutManager"));
5 UIComponentGlobals.layoutManager.usePhasedInstantiation = true;
6
7 if (!FlexGlobals.topLevelApplication)
8 FlexGlobals.topLevelApplication = this;
9
10 super();
11
12 showInAutomationHierarchy = true;
13 }
布局分三个阶段执行:提交、度量和布局。2 {
3 UIComponentGlobals.layoutManager = ILayoutManager(
4 Singleton.getInstance("mx.managers::ILayoutManager"));
5 UIComponentGlobals.layoutManager.usePhasedInstantiation = true;
6
7 if (!FlexGlobals.topLevelApplication)
8 FlexGlobals.topLevelApplication = this;
9
10 super();
11
12 showInAutomationHierarchy = true;
13 }
那作为一个组件,是怎么样 参与到布局策略中呢?
flex中所有的组件都继承自UIComponent类,在该类上实现了一个叫IInvalidating的接口:
public interface IInvalidating
{
function invalidateProperties():void;
function invalidateSize():void;
function invalidateDisplayList():void;
function validateNow():void;
}
当组件调用invalidateProperties方法,表明该组件一个属性发生变化,需要更新.{
function invalidateProperties():void;
function invalidateSize():void;
function invalidateDisplayList():void;
function validateNow():void;
}
它会在方法体写上这么一句:
UIComponentGlobals.layoutManager.invalidateProperties(this);
来告诉布局管理器(LayoutManager),布局管理器在适当的时候回调组件上的validateProperties()验证属性,
如果有属性有变化,进而再调用commitProperties()提交变化的属性.
同理,
调用invalidateSize()告诉布局管理器组件大小发生了变化.
调用invalidateDisplayList()告诉布局管理器组件布局发生了变化.