我已經完成了大量的研究並閱讀Adobe Live Docs,直到我的眼睛流血,試圖弄清楚這一點。Flex:ActionScript中的自定義複合組件 - 存在百分比/百分比高度的問題
我在構建ActionScript中的組合自定義組件,並希望水平佈局子控件。這可以正常工作,將它們添加到HGroup
並將HGroup添加到組件中,問題隨基於百分比的大小而定。
我需要_horizontalGroup:HGroup
根據其容器大小自行調整大小。
逐句通過代碼示出了每個也是UIComponent的父屬性是...
- _horizontalGroup.parent = ReportGridSelector
- ReportGridSelector.parent = grpControls
如果grpControls具有顯式大小,不應該ReportGridSelector也有它的大小?
自定義組件是這樣實現的...
注:ReportControl擴展UIComponent的,不包含任何大小的邏輯
public class ReportGridSelector extends ReportControl{
/*other display objects*/
private var _horizontalGroup:HGroup;
public function ReportGridSelector(){
super();
percentHeight = 100;
percentWidth = 100;
}
override protected function createChildren():void{
super.createChildren();
if(!_horizontalGroup){
_horizontalGroup = new HGroup();
//I WANT SIZE BY PERCENTAGE, BUT THIS DOESN'T WORK
_horizontalGroup.percentWidth = 100;
_horizontalGroup.percentHeight = 100;
//EXPLICITLY SETTING THEM WORKS, BUT IS STATIC :-(
//_horizontalGroup.width = 200;
//_horizontalGroup.height = 200;
addChild(_horizontalGroup);
}
}
}
消費MXML代碼
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup id="grpControls" width="200" height="200">
<ReportControls:ReportGridSelector width="100%" height="100%"/>
</s:VGroup>
如果我明確地定義_horizontalGroup
的width
和height
屬性,一切都顯示正常。如果我嘗試_horizontalGroup.percentWidth
或percentHeight
,所有的控件都會被擠在一起。
有什麼想法是怎麼回事?
此處還有一些我已經找到的相關文章。 [Flex:CreateNewComponent](http://stackoverflow.com/questions/489024/flex-how-to-create-an-entirely-new-component) [Flex Custom Component PercentWidth/Height](http:// stackoverflow。 com/questions/2473085/flex-custom-component-percentage-width-height) [如何獲取Flex組件以使用ActionScript填充可用空間](http://stackoverflow.com/questions/2090845/how-to-get -flex-components-to-fill-available-space-using-actionscript) – DynaWeb