Hi,

In the IDE for "Input" text fields, you can fill it with "m" characters ("M" if you are allowing uppercase input). Then count the number of m's that fit in your space for that font size and set the "Maximum Characters" property of the text field in the IDE (TextField.maxChars is the corresponding AS property). FYI - "m" is usually the widest character in the font which is why they use "em" for font measurement; (1em = width of the "m")

If you are using pure AS code, you can calculate the width in a similar way when you create the text field, by filling it with m's until your width is reached.

   for example (untested):

   var calculatedSize:Boolean = false;
   var fmt:TextFormat = myTf.getTextFormat();
   var padding:int = 4;//standard padding for TextFields
//This is how wide your text field can be - you could pass this into a class if your TF does not know the size of the thing it's supposed to match.
   var desiredWidth:int = 50;
   var maxChars:int = 0;
//Go in a loop adding characters until the width of our text exceeds our "desired" width.
    do {
myTf.appendText("m"); //not 100% sure, but think you may have to call this to ensure your input text gets formatted nicely when you add chars. myTf.setTextFormat(fmt); maxChars++;
      if ((desiredWidth - padding) < myTf.textWidth) {
         maxChars--;
         calculatedSize = true;
      }

   } while(false == calcutedSize)
myTf.maxChars = maxChars;
   myTf.text = "";

   HTH

   Glen
ktt wrote:
Hello,

TextFiled is placed on a larger box A. How to limit input to TextField, when it 
touches(visualy) one of the box sides? TextField is not a child of a box A.


Regards,
ktt


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


--

Glen Pike
01326 218440
www.glenpike.co.uk <http://www.glenpike.co.uk>

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to