Страница 1 из 1

Проблема с циклом for

Добавлено: 28 дек 2010, 23:49
Doker
Имеется такой код.

Код: Выделить всё

                ans_clips.ans_clip1.name_tf.text=xmlData.question[0].user_id.toString();                ans_clips.ans_clip1.question_tf.text=xmlData.question[0].question.toString();                ans_clips.ans_clip1.bank_tf.text=xmlData.question[0].bank.toString();                ans_clips.ans_clip1.count_b_tf.text=xmlData.question[0].count_b.toString();                                ans_clips.ans_clip2.name_tf.text=xmlData.question[1].user_id.toString();                ans_clips.ans_clip2.question_tf.text=xmlData.question[1].question.toString();                ans_clips.ans_clip2.bank_tf.text=xmlData.question[1].bank.toString();                ans_clips.ans_clip2.count_b_tf.text=xmlData.question[1].count_b.toString();                                ans_clips.ans_clip3.name_tf.text=xmlData.question[2].user_id.toString();                ans_clips.ans_clip3.question_tf.text=xmlData.question[2].question.toString();                ans_clips.ans_clip3.bank_tf.text=xmlData.question[3].bank.toString();                ans_clips.ans_clip3.count_b_tf.text=xmlData.question[3].count_b.toString();                                ans_clips.ans_clip4.name_tf.text=xmlData.question[4].user_id.toString();                ans_clips.ans_clip4.question_tf.text=xmlData.question[4].question.toString();                ans_clips.ans_clip4.bank_tf.text=xmlData.question[4].bank.toString();                ans_clips.ans_clip4.count_b_tf.text=xmlData.question[4].count_b.toString();                                ans_clips.ans_clip5.name_tf.text=xmlData.question[5].user_id.toString();                ans_clips.ans_clip5.question_tf.text=xmlData.question[5].question.toString();                ans_clips.ans_clip5.bank_tf.text=xmlData.question[5].bank.toString();                ans_clips.ans_clip5.count_b_tf.text=xmlData.question[5].count_b.toString();
ans_clip1,ans_clip2,ans_clip3,ans_clip4,ans_clip5 находятся внутри муви клипа ans_clips. Нужно циклом for уменьшить обьем кода до минимума.
Проблема вот в чем.

Код: Выделить всё

 var m:uintfor (m=1; m<5; m++)            {                ans_clips.ans_clip[m].name_tf.text=xmlData.question[m-1].user_id.toString();                ans_clips.ans_clip[m].question_tf.text=xmlData.question[m-1].question.toString();                ans_clips.ans_clip[m].bank_tf.text=xmlData.question[m-1].bank.toString();                ans_clips.ans_clip[m].count_b_tf.text=xmlData.question[m-1].count_b.toString();}
Ничего не происходит. ans_clip[m] поидее так нельзя, т.к. это название муви клипа. Как это реализовать правельно?

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 05:06
bodnar
может

Код: Выделить всё

ans_clip["ans_clip"+m].name_tf

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 08:50
butuz
может

Код: Выделить всё

getChildByName("ans_clip"+m) as MovieClip

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 13:29
Doker
bodnar писал(а):может

Код: Выделить всё

ans_clip["ans_clip"+m].name_tf
нет

butuz писал(а):может

Код: Выделить всё

getChildByName("ans_clip"+m) as MovieClip
нет



=(

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 14:19
bodnar
что значит нет, только что проверял
a - movieclip
b- кнопка внутри мувика

Код: Выделить всё

 trace(a);        //[object MovieClip]trace(a.b);     //[object SimpleButton]trace(a["b"]); //[object SimpleButton] 

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 15:10
butuz
bodnar, +1

тоже свой способ проверил, работает если не забыть имена дать своим мувикам

test.zip
http://www.ex.ua/view_storage/141920117869

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 19:18
Doker
butuz, так нужно же к текстовому полю обратиться.

bodnar, спасибо. просто когда пробовал твой код, оказывается хост глючил. и ты написал
ans_clip["ans_clip"+m].name_tf.text
а надо было
ans_clips["ans_clip"+m].name_tf.text
а я тупо скопировал код, поэтому и не работало)

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 22:16
butuz
Doker писал(а):butuz, так нужно же к текстовому полю обратиться.
а что мешает? мы же получили свои мувики в цикле со всеми потрохами

добавил поля для примера test1.zip
m.name_tf.text = m.name;

http://www.ex.ua/view_storage/141920117869

Re: Проблема с циклом for

Добавлено: 29 дек 2010, 22:49
Doker
Спасибо конечно, но я уже сделал как написал bodnar.