在 Flex 中,假设我有一个超类……比如:
class SuperComponent extends DragStack {
private var _childReference:UIComponent;
public function SuperComponent() {
// ???
addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
}
private function onCreationComplete(e:FlexEvent):void {
//The 'this[]' technique doesn't seem to work and causes run-time errors:
//trace("Component found: " + this["myButton"]);
}
}
然后我在我的应用程序中使用了以下派生类(仅以 MXML 模型为例):
<!-- Component ChildComponent.mxml -->
<mx:SuperComponent>
<mx:Button id="myButton" label="Press Me!" />
</mx:SuperComponent>
如何从 SuperComponent 类中验证“myButton”是否存在并引用它?我需要使用 getChildByName( ... ) 吗?