actionscript 3 - AS3 flash CC I want to set the width of the parent Movieclip of a Textfield -


i have dynamically created bunch of textfields, number of depends on xml input. textfields need button-enabled, thought easiest solution put them in movieclip , buttonmode movieclip.

the hierarchy looks this: main (extends movieclip) -> klankoefening (a movieclip) -> textfieldparent (a movieclip) -> textfield

i have variable maxw contains biggest textfield's width , want textfieldparents have width.

i'm trying this:

//generate textfields keuzes = new xmllist(lijstopties.categorie.(@cat == catname)); var nrs:int = keuzes.keuze.length(); //aantal keuzemogelijkheden var maxw:int = 0; //grootste breedte tf, nodig voor bepalen breedte knoppen  (var nr:int = 0; nr < nrs; nr++) {      var tf:textfield = createtextfield(werkfmt);     tf.text = keuzes.keuze[nr].tostring();     tf.autosize = "center";     tf.background = true;     tf.backgroundcolor = 0xffcc33;     tf.border = true;     tf.bordercolor = 0x000000;     tf.name = "keuzetf";     tf.selectable = false;     tf.x = 0;     tf.y = 0;      if (tf.width > maxw) {maxw = tf.width;}      var tfcontainer:movieclip = new movieclip();     tfcontainer.buttonmode = true;     tfcontainer.name = keuzes.keuze[nr].tostring();     tfcontainer.addchild(tf);      klankoefening.addchildat(tfcontainer,nr); }  (var an:int = 0; < 3; an++) {     var mcs:movieclip = klankoefening.getchildat(an) movieclip;     mcs.width = maxw;     trace ("mcs " + mcs.width);      var mtf:textfield = mcs.getchildat(0) textfield;             trace ("mtf " + mtf.text); } 

the trace results

mcs 32.05 mcs 33 mcs 21.25 

which find odd, because stated in second loop width textfieldparents should set maxw. happening?

consider drawing underlaying rectangle of desired width , height. can use mcs.graphics that. trick is, width of displayobjectcontainer calculated property, , changing result in changing scale. say, mc has 2 shapes chilren, 1 @ (1000,0) , @ (0,0), , both have width of 10 - resultant width of mc 1010. so, instead of changing width, simulate change drawing rectangle on mc.

mcs.graphics.clear(); mcs.graphics.linestyle(0,0,0); mcs.graphics.beginfill(0x808080,0); // bogus filled rect, capture events mcs.graphics.drawrect(0,0,maxw,maxh); // height needed mcs.graphics.endfill(); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -