开发者

flex 4 add button

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();
                bu开发者_Go百科tton2.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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜