PDA

View Full Version : child UIComponent doesn't work, when added in draw method


s8000_1
11-04-2008, 04:21 PM
Why does upper button "bt1" not working?

package {
import flash.display.Sprite;
import fl.controls.Button;
public class StageTest extends Sprite{

public function StageTest() {
var testC:TestComp = new TestComp();
addChild(testC);

var bt2:Button = new Button();
bt2.label = "bt2";
bt2.y = 30;
addChild(bt2);
}
}
}

import fl.controls.Button;
import fl.core.UIComponent;
class TestComp extends UIComponent {
private var bt1:Button;

public function TestComp() {
bt1 = new Button();
bt1.label = "bt1";
//addChild(bt1); // if uncomment, button will work
}

override protected function draw():void {
addChild(bt1);
bt1.drawNow();
super.draw();
}
}