0

私は as3 flash にテキストフィールドとラジオボタンを備えたフォームを持っており、それらの「インスタンス名」はすべて次のように連続して設定されています: field_1 field_2 field_3 ...など

AS3 コードでこれらすべてのフィールドをループして、それらの値を配列で取得する簡単な方法はありますか? 理想的には、単にループして値を取得し (値が欠落している場合は単純なポップアップを追加できるようにするため)、埋められた配列を URLRequest を使用して投稿するだけです。

ありがとう!

4

2 に答える 2

1

少し手間がかからず、より保守しやすい方法が必要な場合 (テキストの量が将来変更される可能性がある場合、または他のフォームでコードを再利用する必要がある場合、またはインスタンス名に煩わされたくない場合)、次のことができます。以下のコードのようなもの。

これは、すべてのテキスト フィールドが同じ親の子であり、その親のスコープ内にあることを前提としていることに注意してください (すべてのテキスト フィールドを保持するタイムラインのフレーム上)。

function validateTextFields(){
    var tmpTf:TextField;
    var i:int = numChildren;
    while(i--){ //iterate through all the display objects on this timeline
        tmpTf = getChildAt(i) as TextField;
        if(tmpTf){
            //now that you have the textfield, you can check for an appropriate value, or send the value to a server, or store it in an array etc.

            //check if the value is blank, if so set the background to red
            if(tmpTf.text == ""){
                tmpTf.background = true;
                tmpTf.backgroundColor = 0xFF0000;
            }else{
                tmpTf.background = false;
            }
        }
    }
}
于 2012-11-01T20:16:07.977 に答える
0

for文を使いたいようです。また、多次元配列を使用して、インスタンス名とそれに含まれるテキストを格納しました。変数 _path を使用して、コードのスコープを定義するのが好きです。

var _path = this;
var text_ar:Array = new Array(['instance_1',''],['instance_2',''],['instance_3','']);    //instance name, instance text.

for(var i=0; i<ar.length; i++)
{
     text_ar[i][1] = _path[text_ar[i][0]].text
}

trace( text_ar[1][1] ); //Traces the text that's entered in instance_1. 
于 2012-11-01T15:01:24.303 に答える