无法在FLEX中设置容器的背景颜色属性

时间:2013-06-03 09:17:30

标签: flex actionscript mxml

var newHBox:VBox = new VBox();
newHBox['width'] = 20;
newHBox['height'] = 30;
newHBox['backgroundColor'] = "#FF0000";
container.addChild(newHBox);

var newHBox:VBox = new VBox();
newHBox.width = 20;
newHBox.height = 30;
newHBox.backgroundColor = "#FF0000";
container.addChild(newHBox);

我无法理解为什么我无法设置backgroundColor属性,我收到错误:

access of possibly undefined property through a reference with static type mx.containers.VBox

如果我使用第一个代码示例,那么没有错误,但backgroundColor仍然不适用,styleName适用得很好,你能告诉我为什么无法设置backgroundColor吗? / p>

1 个答案:

答案 0 :(得分:1)

backgroundColor是样式属性,因此您应该使用:

newHBox.setStyle("backgroundColor", 0xFF0000);