Flex中的組件(Component)有三個屬性, 通常用來引用上級的對象, 它們是 Parent, ParentDocument, ParentApplication.
1. Parent:指包含此組件的父級容器對象(DisplayObjectContainer), 這里的包含是詞義上(Lexical)的包含. DisplayObjectContainer是一個抽象類, 是所有能夠包含子對象(child objects)的父類.
The DisplayObjectContainer class is an abstract base class for all objects that can contain child objects. It cannot be instantiated directly; calling the new DisplayObjectContainer() constructor throws an ArgumentError exception.
Inheritance: UIComponent-> FlexSprite-> Sprite-> DisplayObjectContainer-> InteractiveObject-> DisplayObject-> EventDispatcher-> Object
2. ParentDocument:指向包含此組件的父文檔對象. 這里關鍵點是 什么是文檔對象? 文檔對象是頂層的Flex程序, MXML組件或者AS組件, 其類型必須是UIComponent, 所以, Document一般指代的是自定義組件的根結點或者程序的Application結點. 它和Parent的區別是在于, 它不是詞義上的父對象, 而是父文檔. 例如我們自定義一個繼承Panel的MXML組件, FormItem的Parent是Form, 而FormItem 和Form 的ParentDocument則都是Panel.
2 | < mx:Form width = "100%" height = "100%" > |
A reference to the parent document object for this UIComponent. A document object is a UIComponent at the top of the hierarchy of a Flex application, MXML component, or AS component. For the Application object, the parentDocument property is null. This property is useful in MXML scripts to go up a level in the chain of document objects. It can be used to walk this chain using parentDocument.parentDocument, and so on. It is typed as Object so that authors can access properties and methods on ancestor document objects without casting.
3. ParentApplication:指向包含此組件的 Application 對象. 通常一個Flex程序包含在標簽中, 但這個程序又可能會作為一個模塊(moduler)存在于更大的程序中. ParentApplication則指向了包含此組件的”最近”的Application 對象, 當存在更上一層的Application 對象時, 可以通過ParentApplication.ParentApplication這樣的鏈接來存取.
A reference to the Application object that contains this UIComponent instance. This Application object might exist in a SWFLoader control in another Application, and so on, creating a chain of Application objects that can be walked using parentApplication. The parentApplication property of an Application is never itself; it is either the Application into which it was loaded or null (for the top-level Application).