Flex 4 添加按钮
我有这段代码,没有显示任何错误,但无法工作;你能帮助我吗?我只想在我的表单上放置新按钮:
minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.Button;
function onClick() {
var button2:mx.controls.Button = new mx.controls.Button();
button2.x = 100;
button2.y = 100;
Form1.addChild(button2);
}
]]>
</fx:Script>
<s:Form id="Form1" x="0" y="0" width="100%" height="100%">
<s:Button id="button1" label="button1" click="onClick()" />
</s:Form>
</s:Application>
i have this code that doesn't show any error but can't work; can you help me? i just want to place new button on my form:
minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.Button;
function onClick() {
var button2:mx.controls.Button = new mx.controls.Button();
button2.x = 100;
button2.y = 100;
Form1.addChild(button2);
}
]]>
</fx:Script>
<s:Form id="Form1" x="0" y="0" width="100%" height="100%">
<s:Button id="button1" label="button1" click="onClick()" />
</s:Form>
</s:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我尝试运行它时出现运行时异常。
这应该可以解决问题:
使用 Spark 容器,您需要执行 addElement() 而不是 addChild();
您可以在 adobe livedocs 中找到有关使用 Spark 组件的更多信息,网址为 http: //help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff9.html
干杯
There was a runtime exception when I tried to run this.
This should do the trick:
With Spark containers you need to do addElement() instead of addChild();
You can find more information about working with spark components in the adobe livedocs at http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff9.html
Cheers