PDA

View Full Version : textboxes in loop


chaitanya
07-08-2008, 04:38 AM
Hi , wht i need is , on click of a button, i should get the values of the texbox if and only if, it is filled with some no, i want to keep all this in loop, can anyone suggest me...........
Here i have 4 textboxes and 4 color pickers, if i change color in colorpicker the no will be displayed in the textbox, if i click on the button, i should get the values of the filled textboxes. that should be displayed in the textarea...........


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>
<![CDATA[
public var sk_list:String = "";
public function changeColor(txt:Object,color:Object):void
{
txt.text = uintToHex(color.selectedColor)
}

private function uintToHex(value:uint):String
{
var prefix:String = "000000";
var str:String = String(prefix + value.toString(16));
return "0x"+ str.substr(-6).toUpperCase()
}
private function onClick():void
{
for(var i:Number=1;i<=4;i++)
{
if(("t"+i).length !=0)
{
sk_list += ("sk_color"+i)+"="+['t'+i].text;
ta.text = sk_list;
}
}
}
]]>
</mx:Script>



<mx:TextInput x="109" y="119" width="80" id="t1"/>
<mx:TextInput x="109" y="149" width="80" id="t2"/>
<mx:TextInput x="109" y="179" width="80" id="t3"/>
<mx:TextInput x="109" y="209" width="80" id="t4"/>
<mx:ColorPicker x="209" y="119" id="cp1" change="changeColor(t1,cp1)"/>
<mx:ColorPicker x="209" y="149" id="cp2" change="changeColor(t2,cp2)"/>
<mx:ColorPicker x="209" y="179" id="cp3" change="changeColor(t3,cp3)"/>
<mx:ColorPicker x="209" y="209" id="cp4" change="changeColor(t4,cp4)"/>
<mx:Button x="357" y="94" label="Click" id="b" click="onClick()"/>
<mx:TextArea x="314" y="124" id="ta" height="107"/>

</mx:Application>

chaitanya
07-08-2008, 04:39 AM
Hi , wht i need is , on click of a button, i should get the values of the texbox if and only if, it is filled with some no, i want to keep all this in loop, can anyone suggest me...........
Here i have 4 textboxes and 4 color pickers, if i change color in colorpicker the no will be displayed in the textbox, if i click on the button, i should get the values of the filled textboxes. that should be displayed in the textarea...........


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>
<![CDATA[
public var sk_list:String = "";
public function changeColor(txt:Object,color:Object):void
{
txt.text = uintToHex(color.selectedColor)
}

private function uintToHex(value:uint):String
{
var prefix:String = "000000";
var str:String = String(prefix + value.toString(16));
return "0x"+ str.substr(-6).toUpperCase()
}
private function onClick():void
{
for(var i:Number=1;i<=4;i++)
{
if(("t"+i).length !=0)
{
sk_list += ("sk_color"+i)+"="+['t'+i].text;
ta.text = sk_list;
}
}
}
]]>
</mx:Script>



<mx:TextInput x="109" y="119" width="80" id="t1"/>
<mx:TextInput x="109" y="149" width="80" id="t2"/>
<mx:TextInput x="109" y="179" width="80" id="t3"/>
<mx:TextInput x="109" y="209" width="80" id="t4"/>
<mx:ColorPicker x="209" y="119" id="cp1" change="changeColor(t1,cp1)"/>
<mx:ColorPicker x="209" y="149" id="cp2" change="changeColor(t2,cp2)"/>
<mx:ColorPicker x="209" y="179" id="cp3" change="changeColor(t3,cp3)"/>
<mx:ColorPicker x="209" y="209" id="cp4" change="changeColor(t4,cp4)"/>
<mx:Button x="357" y="94" label="Click" id="b" click="onClick()"/>
<mx:TextArea x="314" y="124" id="ta" height="107"/>

</mx:Application>

box86rowh
07-08-2008, 03:31 PM
your issue lies in your for loop,
you cant access an object using strings, you can use getChildByName("t" + i).length
to get the length of the text, and getChildByName("t" + i).text to get the text.

chaitanya
07-09-2008, 05:38 AM
Thanks for replying, but the length and text property are not working for this getChildByName

the errors are

Access of possibly undefined property length through a reference with static type flash.display:DisplayObject.

Access of possibly undefined property text through a reference with static type flash.display:DisplayObject.