2012-09-14 59 views
2

我想在AS3單選按鈕的標籤高度。
如何獲得一個單選按鈕的標籤高度 - AS3

我在單選按鈕組5個單選按鈕。其中一個radioButtons有一個三線標籤,另一個有一個單線等...

當我嘗試訪問radioButton.height時,無論標籤高度如何,我都會得到相同的值。

我需要知道標籤的高度,這樣我就可以設置單選按鈕Ÿ相應座標。

我可以改變單選按鈕的標籤高度?

spacing = 30; 
rb.label = tempQQString //from xml. long or short string anyone 
rb.group = myGroup; 
rb.value = i + 1; 

rb.x = answerX; 
rb.y = questionField.height + (questionY+20) + (i * spacing); // here use rb.height or rb.textField.height 

trace("rb height**" + rb.height) // always get velue 22; 
addChild(rb); 
+0

是的,有時候,像radioButton這樣的fl控件會覆蓋真正的高度,所以它忽略了標籤...... – BadFeelingAboutThis

+0

你使用了什麼單選按鈕類?你會不會用'rb.height',它代表着整個單選按鈕組件的高度得到的單選按鈕標籤高度,標籤是單選按鈕的孩子也有自己的高度。 –

+0

沒有必要的答案。 rb.textField.height是獲取radioButton標籤的高度。 Thanx :) –

回答

-1

試試這個。

for(var i=0;i<rb.numChildren;i++){ 
    if(rb.getChildAt(i) is TextField){ 
     var txt:TextField = rb.getChildAt(i) as TextField; 
     trace(txt.height+":"+rb.height);//traces the height of text field and radio button 
    } 
} 
0

單選按鈕和擴展的LabelButton(所有有標籤的)任何FL控制,暴露的實際文本字段與.textField財產。

因此,對於您的示例,而不是使用rb.height,您將使用rb.textField.height來獲取控件的標籤部分的高度。

您還可以設置在文本框屬性爲好。

rb.textField.background = true; 
rb.textField.backgroundColor = 0xDDDDDD; 

rb.textField.multiline = true; 
rb.textField.wordWrap = true; 
rb.textField.autoSize = TextFieldAutoSize.LEFT; 

現在,爲您的方案,你可能會更好只使用單選按鈕的邊界,而不是,因爲這將是該對象的REAL高度。

rb.getBounds(rb).height; //this will be the true height of the component. 

如果您的標籤是一條線,你的圖標是不是你的標籤高,你可能會得到來自rb.textField.height值比​​單選按鈕的實際高度。

+0

thanx回答:)我不知道「rb.getBounds(rb).height」代碼。尼斯:) –

+0

請接受答案。這種WAY WAY WAY方式比循環單選按鈕的每個子元素都更有效率和乾淨,直到到達文本字段實例。 – BadFeelingAboutThis

相關問題