Flash Flex4添加按钮

Flash Flex4添加按钮,flash,actionscript,button,Flash,Actionscript,Button,我有这个代码,没有显示任何错误,但无法工作;你能帮助我吗?我只想在表单上放置新按钮: minHeight=“600”> 当我尝试运行此程序时,出现运行时异常 这应该可以做到: protected function onClick():void { var button2:mx.controls.Button = new mx.controls.Button(); //button2.x = 100; These two lines are obsolete because form handl

我有这个代码,没有显示任何错误,但无法工作;你能帮助我吗?我只想在表单上放置新按钮:

minHeight=“600”>

当我尝试运行此程序时,出现运行时异常

这应该可以做到:

protected function onClick():void {
var button2:mx.controls.Button = new mx.controls.Button();
//button2.x = 100; These two lines are obsolete because form handles the layout of its children automatically
//button2.y = 100;
Form1.addElement(button2);
}
对于Spark容器,您需要执行addElement()而不是addChild()

您可以在adobe livedocs中找到有关使用spark组件的更多信息,网址为


干杯

没问题,但是如果您有Flashbuilder并调试了该应用程序,您可以自己发现错误消息。所以请记住调试,它为您提供了一些关于可能出错的线索:)
protected function onClick():void {
var button2:mx.controls.Button = new mx.controls.Button();
//button2.x = 100; These two lines are obsolete because form handles the layout of its children automatically
//button2.y = 100;
Form1.addElement(button2);
}