Flex 4 添加按钮

发布于 2024-11-08 15:50:50 字数 680 浏览 0 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

身边 2024-11-15 15:50:50

当我尝试运行它时出现运行时异常。

这应该可以解决问题:

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 组件的更多信息,网址为 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:

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);
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文