0

実行時に一連のTextFieldsを作成していますが、これには、の高さの取得が非常に不正確htmlTextであるという問題が含まれています。TextField

TextField._heightまたはプロパティにアクセスするTextField.heightと、正確に近くなく、0〜1.5行の高さの間で変化する可能性があります。

TextFieldを空MovieClipにして、MovieClipの高さを取得しようとしましたが、同じ不正確さが返されます。(例に示されています)

関連コード:

var format = new TextFormat();
format.size = 14;
format.align = "left";
format.font = "Arial";
format.color = 0x000000;
format.leading = 3;

var textBoxes:Array = new Array();

function createText(htmlString:String, isOption:Boolean, name:String) {
    var textY:Number;
    if(isOption) {
        var textMC:MovieClip = target.attachMovie("option", "txt_" + textBoxes.length, target.getNextHighestDepth());
        textMC.name.text = name;
    } else {
        var textMC:MovieClip = target.createEmptyMovieClip("txt_" + textBoxes.length, target.getNextHighestDepth());
    }
    var fieldContainer:MovieClip = textMC.createEmptyMovieClip("container", textMC.getNextHighestDepth());
    var textBox:TextField = fieldContainer.createTextField("textBox", fieldContainer.getNextHighestDepth(), studySettings.margin, studySettings.margin, target._width - (studySettings.margin * 2),0);
    textBox.autoSize = true;
    textBox.wordWrap = true;
    textBox.html = true;
    textBox.multiline = true;
    textBox.htmlText = htmlString;
    textBox.setTextFormat(format);
    textBox.embedFonts = true;
    textBox.selectable = false;
    textBox.antiAliasType = "advanced";
    if(isOption) {
        textMC.option = currentOption;
        textMC.enabled = false;
        textBox._y += textMC.background._y;
        textBox._width = textMC._width - (studySettings.margin * 3);
        textMC.background._width = target._width - (studySettings.margin * 2);
        textMC.background._height = fieldContainer._height + (studySettings.margin * 2);
        textMC._x = studySettings.margin;
        textMC.onRollOver = function() {
            this.background.gotoAndStop("over");
        }
        textMC.onRollOut = function() {
            this.background.gotoAndStop("up");
        }
        textMC.onRelease = function() {
            showStudy(study.caseIndex, study.choiceIndex, false, this.option);
            clearStudy(study, false);
        }
    }
    if(textBoxes.length) {
        var prebounds:Object = textBoxes[textBoxes.length - 1].getBounds(target);
        textMC._y = (isOption) ? prebounds.yMax + studySettings.margin : prebounds.yMax;
    } else {
        textMC._y = 0;
    }
    textBoxes.push(textMC);

どうすれば確実にTextField高さを取得できますか?

4

1 に答える 1

0

TextField.textWidth/TextField.textHeight は、フィールドのコンテンツの実際のサイズを返す必要があります。

レイアウトにこれらの測定値を使用している場合、それらは完全ではないことがわかります.TextFieldをテキストコンテンツにスケーリングしている場合は、通常、各寸法に10〜20を追加するか、奇妙な文字を切り取るのが最善です-しかし、これらは現実的な値を返し、幅/高さは寸法を反映しません。

お役に立てれば。

于 2012-10-23T14:59:47.830 に答える