arrays - Finding the biggest width of multiple text fields in AS3 -
i have array makes multiple textfields based off user variable. code below connected function fires when text added. there it's supposed find widest text field, , apply width rest of textfields same size.
here code giving me problems. utilize sec see perhaps if syntax improper or if there's improve way @ going @ this.
for (var ied: int=1; ied>=electoff.electinput.textarray.length; ied++) { trace("one"); widest=(electoff.electinput.textarray["b"+ied].width>widest)?electoff.electinput.textarray["b"+ied].width:widest; } (i =ied; i<electoff.electinput.textarray.length; ied++) { electoff.electinput.textarray["b"+ied].width = widest; trace("two"); }
here's error i'm getting:
typeerror: error #1010: term undefined , has no properties. @ newplv2_fla::maintimeline/ajwidth()[newplv2_fla.maintimeline::frame1:650] @ newplv2_fla::maintimeline/_keys()[newplv2_fla.maintimeline::frame1:774]
as3.0 array indices zero-based, means first element in array [0], sec element [1], , on.
so fyi trying access textarray["b"+ided]
. syntax associative arrays
i tested next code. check please.
import flash.text.textfield; var arr:array = []; for(var i:int = 0; i<10; i++) { var tf:textfield = new textfield(); tf.width = 200 * math.random();; tf.name = "tf" + i; tf.height = 100; arr.push(tf); trace(tf.name + ": " + tf.width); } var widest:number = 0; (i=0;i<arr.length;i++) { if(arr[i].width>widest) widest = arr[i].width; } trace("widest: " + widest);
arrays actionscript-3
No comments:
Post a Comment