我尝试使用以下代码将一个Box添加到我的应用程序中
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
>
<mx:HBox height="100%" width="100%" backgroundColor="red" borderColor="black"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.containers.Box;
import mx.events.FlexEvent;
protected function button1_clickHandler():void
{
var box:Box = new Box();
box.setStyle("backgroundColor","blue");
box.height = 100;
box.width = 100;
//box.addChild(new Button());
addChild(box);
trace("children "+numChildren);
}
]]>
</mx:Script>
<mx:Button label="click" click="button1_clickHandler()" x="200" y="200" />
</mx:Application>此代码在flexBuilder.but中工作,在命令提示符下编译时不工作(使用mxmlc命令)。请在这个问题上建议我,因为我的工作完全依赖于命令提示符。
预先感谢vengatesh s
发布于 2012-03-14 01:46:18
这完全取决于您使用的编译器。如果你使用的是Flex编译器,我建议你尝试使用addElement而不是addChild。上面相同的代码只是更改为
protected function button1_clickHandler():void
{
var box:Box = new Box();
box.setStyle("backgroundColor","blue");
box.height = 100;
box.width = 100;
/********** ----------- CHANGE----------------------********/
// This is the only change from your code
addElement(box);
/********** ----------- CHANGE----------------------********/
trace("children "+numChildren);
}https://stackoverflow.com/questions/9687229
复制相似问题