![]() |
|
||||||||||
|
|||||
|
Регистрация: Jun 2008
Сообщений: 5
|
Есть много текстовых полей.
<mx:Text id="a1" text="-"/> <mx:Text id="a2" text="-"/> <mx:Text id="a3" text="-"/> <mx:Text id="a4" text="-"/> ... Как заполнить эти поля контентом с помощью for-a? Пытался так: Но ессесно ничего не вышло. |
|
|||||
|
Modus ponens
|
<?xml version="1.0"?>
<u:Main xmlns:u="*" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Text;
public var texts:Array = ["foo", "bar", "qwerty", "abcd"];
public function nextText(i:int):String { return texts[i]; }
public function resetFields():void
{
var i:int = numChildren + 1;
var tf:Text;
texts.reverse();
while (i--)
{
if (getChildAt(i) is Text)
{
tf = getChildAt(i) as Text;
texts.unshift(texts.pop());
tf.text = texts[0];
}
}
}
public function randomiseFields():void
{
var i:int = texts.length;
var tf:Text;
texts = randomiseArray(texts);
while (i--) (this["text" + i] as Text).text = texts[i];
}
private function randomiseArray(arr:Array):Array
{
var farr:Array = [];
var i:int = arr.length;
while (i--) farr.push(arr.splice(Math.random() * arr.length, 1)[0]);
return farr;
}
]]>
</mx:Script>
<mx:Button id="reversBTN" label="reverse texts" buttonDown="resetFields()" />
<mx:Button id="randomiseBTN" label="randomise texts" buttonDown="randomiseFields()" />
<mx:Text id="text0" text="{nextText(0)}" width="200" height="50"/>
<mx:Text id="text1" text="{nextText(1)}" width="200" height="50"/>
<mx:Text id="text2" text="{nextText(2)}" width="200" height="50"/>
<mx:Text id="text3" text="{nextText(3)}" width="200" height="50"/>
</u:Main>
__________________
Hell is the possibility of sanity Последний раз редактировалось wvxvw; 21.09.2008 в 00:33. |
|
|||||
|
Регистрация: Dec 2007
Сообщений: 52
|
|
![]() |
![]() |
Часовой пояс GMT +4, время: 15:24. |
|
|
« Предыдущая тема | Следующая тема » |
|
|