2016-04-14 5 views
0

アクションスクリプト3を使用してクイズをフラッシュしています。下のコードは、質問ボックスに収まるように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(); 
+0

私はあなたのための例を書いていきます。 –

答えて

1

おそらくこれを試してください。これは、フレームに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) 

は、上記のメソッドを呼び出すと、あなたの答えの配列を渡しています。これはあなたにアイデアを与えるでしょう。

0

コンテンツを更新した後で、フォントサイズを再度更新する必要があります。最初のフレームで使用しているのと同じコードを使用できるはずです。

+0

私はこれを試したが、それは私に複数の重複と競合のエラーを与える –