actionscript 3 - TextField not appearing in Sprite -


i have sprite contains textfield. then, want create second sprite ("containersprite") same size textfield. that's not difficult , works fine.

now want add third sprite ("innersprite") containersprite. need third sprite because i'm going use drag , drop purposes. add textfield it, , want textfield same width both containersprite , innersprite. depending on how text in textfield, need innersprite resize height accordingly.

this should simple. isn't working. doing wrong?

thanks,

david

package { import flash.display.sprite; import flash.text.textfield; import flash.text.textfieldautosize; import flash.text.textfieldtype;  public class spriteandtextfield extends sprite {     private var innertext:textfield;     private var innersprite:sprite;     private var containersprite:sprite      public function spriteandtextfield()     {         var tf:textfield = new textfield();         tf.type = textfieldtype.input;         tf.width = 300;         tf.height = 200;         tf.x = 0;         tf.y = 100;          tf.selectable = true;         tf.border = true;         tf.background = true;         tf.backgroundcolor = 0xcccccc;         tf.multiline = true;         tf.wordwrap = true;         tf.text = "some text here."         addchild(tf);          //containersprite          containersprite = new sprite();         containersprite.x = tf.x + tf.width + 10;         containersprite.y = tf.y;         containersprite.graphics.beginfill(0xffffff,1 )         containersprite.graphics.drawrect(0, 0, tf.width, tf.height);         containersprite.graphics.endfill();         containersprite.name = "containersprite";         addchild(containersprite);          //now add sprite, textfield. want sprite , textfield contains same width         //as containersprite. innersprite's height should determined text in child         //textfield         innersprite = new sprite();         //not setting x , y, should appear @ 0,0 of parent containersprite         innersprite.width = containersprite.width;         containersprite.addchild(innersprite);          //add textfield inner sprite         innertext = new textfield();         innertext.selectable = true;         innertext.border = true;         innertext.background = true;         innertext.backgroundcolor = 0xffff00;         innertext.multiline = true;         innertext.wordwrap = true;         innertext.text = "the textfield class used create display objects text display , input. dynamic , input text fields in swf file instances of textfield class."         innersprite.addchild(innertext);     }          } } 

ultimately, sprites adjust size match content placed within them. if resizing sprite has displayobject children, you're going end scaling children instead of resizing container.

if textfield's width set width want innersprite be, , add textfield sprite, sprite become width (as long textfield @ 0, 0). similarly, textfield's vertical size increases/decreases, sprite contains it.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -