2

我想在 as3 中获取 radioButton 的标签高度。

我的 radioButton 组中有 5 个单选按钮。其中一个单选按钮有一个三行标签,另一个有一个单行等......

当我尝试访问时radioButton.height,无论标签高度如何,我总是得到相同的值。

我需要知道标签的高度,所以我可以相应地设置 radioButton y 坐标。

我可以更改单选按钮的标签高度吗?

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);
4

2 回答 2

0

RadioButton 和任何扩展 labelButton 的 fl 控件(所有具有标签的控件)都使用该.textField属性公开实际的文本字段。

因此,对于您的示例,rb.height您将使用rb.textField.height获取控件标签部分的高度而不是使用。

您还可以在 textField 上设置属性。

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

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

现在,对于您的场景,您最好只使用单选按钮的边界,因为它将是对象的真实高度。

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

如果您的标签是一行并且您的图标比您的标签高,您可能会从 rb.textField.height 获得一个小于单选按钮实际高度的值。

于 2012-09-14T17:03:33.810 回答
-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 
    }
}
于 2012-09-14T10:49:19.140 回答