如何添加按钮作为

时间:2012-03-22 18:13:34

标签: actionscript-3 actionscript flex4

嗨,我刚开始学习flex和动作脚本。有人可以告诉我,我在这段代码中做错了。

public function createBoxes():void 
{
    //create a Panel 
    var colorsPanel:Panel = new Panel(); colorsPanel.layout = "absolute"; colorsPanel.width = 250; colorsPanel.height = 250;
    //add the Panel to the Application
    addElement(colorsPanel);
    //create a red box 
    var redBox:Canvas = new Canvas(); redBox.x = 70; redBox.y = 70; redBox.width = 50; redBox.height = 50; redBox.setStyle("backgroundColor", 0xFF0000);
    //create a green box 
    var greenBox:Canvas = new Canvas(); greenBox.x = 90; greenBox.y = 90; greenBox.width = 50; greenBox.height = 50; greenBox.setStyle("backgroundColor", 0x00FF00);
    //create a blue box 
    var blueBox:Canvas = new Canvas(); blueBox.x = 100; blueBox.y = 60; blueBox.width = 50; blueBox.height = 50; blueBox.setStyle("backgroundColor", 0x0000FF);
    //add the boxes to the Panel
    var Button:spark.components.Button = new spark.components.Button(); Button.x = 120; Button.y = 60; Button.label ="removeG";
    colorsPanel.addElement(redBox); 
    colorsPanel.addElement(greenBox); 
    colorsPanel.addElement(blueBox);
    colorsPanel.addElement(Button); 
}

感谢

1 个答案:

答案 0 :(得分:0)

我要在这里捅一下...... 您使用的是Spark面板还是Halo面板? 您可以通过查看导入语句来判断 如果你看到这一行:

import spark.components.Panel;

然后你正在使用Spark Panel。在这种情况下,您无法使用字符串设置布局属性。相反,您必须使用扩展LayoutBase的类的实例,例如BasicLayout。但是,如果你看到这一行:

import mx.containers.Panel;

然后你正在使用Halo Panel,我不确定问题是什么 - 你需要更好地描述你期望发生的事情和实际发生的事情之间的区别。如果您遇到某种错误,请发布错误文本。