【问题标题】:How to add a button in as如何在 as 中添加按钮
【发布时间】:2012-03-22 18:13:34
【问题描述】:

您好,我刚开始学习 flex 和 action 脚本。谁能告诉我我在这段代码中做错了。

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

谢谢

【问题讨论】:

  • 问题是什么?不编译?不___?
  • 你的代码有什么问题?我刚刚测试过,效果很好,所以问题可能出在其他地方。
  • 抱歉,我不知道发生了什么,但它现在可以工作了 :))

标签: actionscript-3 actionscript flex4


【解决方案1】:

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

import spark.components.Panel;

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

import mx.containers.Panel;

那么您使用的是 Halo 面板,但我不确定问题出在哪里 - 您需要更好地描述您期望发生的事情与实际发生的事情之间的区别。如果您遇到某种错误,请发布错误的文本。

【讨论】:

  • 我使用 mx.containers.Panel;我在应用程序上放了一个按钮。单击此按钮应加载面板,其中包含三个不同颜色的框和另一个按钮。它没有发生我在浏览器中得到错误 #2032
猜你喜欢
  • 2016-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多