2012-03-22 53 views
0

嗨,我刚刚开始学习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); 
} 

感谢

+0

什么是**问题**?不编译?不___? – 2012-03-22 18:15:58

+0

你的代码有什么问题?我刚刚测试过,效果很好,所以问题可能在其他地方。 – sch 2012-03-22 18:27:54

+0

对不起,我不知道发生了什么,但它现在工作:)) – Max 2012-03-22 18:35:11

回答

0

我要在这里采取刺伤它... 您使用的是星火面板或晕面板? 您可以通过查看您的进口报表来查看。
如果你看行:

import spark.components.Panel; 

然后您使用的是星火面板。在这种情况下,您不能使用字符串设置布局属性。相反,您必须使用扩展LayoutBase的类的实例,例如BasicLayout。但是,如果你看到这行:

import mx.containers.Panel; 

然后你使用的是晕面板,我不知道是什么问题 - 你需要更好地描述之间你所期望的差异发生和实际发生的事情。如果您遇到某种错误,请发布错误文本。

+0

我使用mx.containers.Panel;我在应用程序上放置一个按钮。点击这个按钮应该加载面板白色三个不同颜色的框和另一个按钮。它不会发生我在浏览器中获得错误#2032 – Max 2012-03-22 18:41:24

相关问题