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).