Flex动态添加组件例子 Flex如何动态添加组件
Flex动态增加组件的例子,请复制代码运行查看效果,请注意背景颜色不能用vbox.backgroundColor = randColor 得到,要使用vbox.setStyle("backgroundColor", randColor);
</mx:Application>
Flash动画
在线播放
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.containers.VBox;
private function addAccordionChild():void {
var vbox:VBox = new VBox();
vbox.label = "child " + accordion.numChildren;
vbox.percentWidth = 100;
vbox.percentHeight = 100;
var randColor:uint = Math.random() * 0xFFFFFF;
vbox.setStyle("backgroundColor", randColor);
accordion.addChild(vbox);
}
private function removeAccordionChild():void {
if (accordion.selectedChild) {
accordion.removeChild(accordion.selectedChild);
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Add child"
click="addAccordionChild();" />
<mx:Button label="Remove Child"
click="removeAccordionChild();" />
</mx:ApplicationControlBar>
<mx:Accordion id="accordion" width="250" height="100%" />
原文地址:http://www.favzone.com/trackback.asp?tbID=70&action=addtb&tbKey=cf76b77765781061adaf58db8b4b9b39abe6e05b</textarea>