Why my composite component adds an internal component twice?
Şubat 2, 2011 Yorum yapın
Once, I tried to add a component into my composite component by overriding its createChildren method.
I have added it successfully but wait, sometimes, it added this component twice.
This was remarkably surprising. Then I investigated this issue and figured that out:
Internal component might be added by the super class before createChildren method of your subclass. So we have two options to prevent this weird behavior:
1- Be sure that you call super.createChildren() in the very end of subclasses overridden createChildren method:
override protected function createChildren():void{
var objectList:DropDownList = new DropDownList();
addChild(objectList);
super.createChildren();
}
2 – Null check the component you wanna add after defining it as a class property:
protected var objectList:DropDownList = new DropDownList();
override protected function createChildren():void{
if(!objectList){
addChild(objectList);
}
super.createChildren();
}
