如何通过关键帧继续格式化框

How to continue formatting of box through key frames

我正在使用动作脚本 3 在 Flash 中进行测验。如果超过 2 行,下面的代码会使文本变小,以便适合问题框。这行得通!但是,当您更改关键帧时,框的格式也会更改。例如,当问题出现时,字体会发生变化,但当您回答问题并且关键帧发生变化时,字体会发生变化,使其溢出边缘。

如何让格式在关键帧上继续。

这是游戏的动作。

var smallLimit:int = 1;
var format:TextFormat = new TextFormat();


myTextField11.text = shuffledAnswers1[0];   //puts into the text boxes the random answers
myTextField21.text = shuffledAnswers1[1];
myTextField31.text = shuffledAnswers1[2];
myTextField41.text = shuffledAnswers1[3];

var testSize11:int = 25;
var testSize21:int = 25;
var testSize31:int = 25;
var testSize41:int = 25;

while( testSize11 > smallLimit ){

    updateFormat11( testSize11 );
    trace( myTextField11.numLines  );

    if( myTextField11.numLines > 1){
        testSize11--;
    }else{
        testSize11 = smallLimit;
    }
}
while( testSize21 > smallLimit ){

    updateFormat21( testSize21 );
    trace( myTextField21.numLines  );

    if( myTextField21.numLines > 1){
        testSize21--;
    }else{
        testSize21 = smallLimit;
    }
}
while( testSize31 > smallLimit ){

    updateFormat31( testSize31 );
    trace( myTextField31.numLines  );

    if( myTextField31.numLines > 1){
        testSize31--;
    }else{
        testSize31 = smallLimit;
    }
}
while( testSize41 > smallLimit ){

    updateFormat41( testSize41 );
    trace( myTextField41.numLines  );

    if( myTextField41.numLines > 1){
        testSize41--;
    }else{
        testSize41 = smallLimit;
    }
}

function updateFormat11(size11:int):void{
    format.size = size11;
    myTextField11.setTextFormat( format );
    }
function updateFormat21(size21:int):void{
    format.size = size21;
    myTextField21.setTextFormat( format );
}
function updateFormat31(size31:int):void{
    format.size = size31;
    myTextField31.setTextFormat( format );
    }
function updateFormat41(size41:int):void{
    format.size = size41;
    myTextField41.setTextFormat( format );

}

这是在文本框中设置问题的关键帧 2。

myTextField11.text = shuffledAnswers1[0];  
myTextField21.text = shuffledAnswers1[1];
myTextField31.text = shuffledAnswers1[2];
myTextField41.text = shuffledAnswers1[3];
stop();

更新内容后需要再次更新字体大小。您应该能够使用与第一帧中相同的代码。

也许试试这个。这假设您在框架上有 4 个文本字段和 4 个答案的数组。

//Frame 1
var smallLimit:int = 1;
//put all your answer fields in array
var tFields:Array = [myTextField11,myTextField21,myTextField31,myTextField41]
var format:TextFormat = new TextFormat();
//your default font size
var defaultFontSize:int = 25;

function updateAnswerText( value:Array  )
{
    var fontSize:int = defaultFontSize;
    for(var i in tFields )
    {
        //reset to default
        fontSize = defaultFontSize;
        //add text
        tFields[i].text = value[i];
        //setformat
        updateTextFormat( tFields[i] , fontSize)
        //are we overflow
        while( tFields[i].numLines > 1 && fontSize > smallLimit)
        {
            --fontSize;
            updateTextFormat( tFields[i] , fontSize)
        }
    }
}
function updateTextFormat( field:TextField, value:int)
{
    format.size = value;
    field.setTextFormat( format );
}
updateAnswerText( shuffledAnswers1 )

//每一帧都有答案文本框

var tFields:Array = [myTextField11,myTextField21,myTextField31,myTextField41]
updateAnswerText( shuffledAnswers1 )

调用上述方法并传递您的答案数组。这会给你一个想法。