我正在嘗試定義擴展mx:VBox的自定義組件的內容區域。該組件具有預定義的頁眉和頁腳(可視化子項),我想設置中間區域以將子項添加到組件。該組件將如下使用:在自定義柔性組件中設置內容區域
<custom_component>
<mx:button/>
</custom_component>
如何設置此內容區域?
我正在嘗試定義擴展mx:VBox的自定義組件的內容區域。該組件具有預定義的頁眉和頁腳(可視化子項),我想設置中間區域以將子項添加到組件。該組件將如下使用:在自定義柔性組件中設置內容區域
<custom_component>
<mx:button/>
</custom_component>
如何設置此內容區域?
有實際上是幾步就到了。
所以,你的自定義組件會是這個樣子:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Metadata>
[DefaultProperty("content")]
</mx:Metadata>
<mx:HBox id="headerBox"/>
<mx:VBox id="contentBox"/>
<mx:HBox id="footerBox"/>
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private var _contentChildren:Array;
public function set content(c:*) : void {
// Allow 1 or more children to be specified
_contentChildren = (c as Array) || [c];
}
override protected function createChildren() : void {
// Call super so contentBox gets created first
super.createChildren();
for each (var child:UIComponent in _contentChildren) {
contentBox.addChild(child);
}
}
]]>
</mx:Script>
</mx:VBox>
嘗試使用畫布?
在您的自定義組件,添加DefaultProperty元數據標籤:
[DefaultProperty("nameOfDefaultProperty")]
然後,你還要定義一個setter該屬性:
public function set nameOfDefaultProperty(value:UIComponent):void
{
if (value != null)
{
// add "value" to the display list here
}
}
+ 1,處理> 1個孩子的好方法。 – 2009-12-11 19:46:01