Hey Glen thanks for your matter

Actually I found a better way, working in my case. Not sure if its bullet
proof, but so far, its quite okay.

the line to look for is
var formatSize:int = Config.defautltFontSize * (cw / item.width)

variables:
var cw:Number = textField container width
Config.defautltFontSize = 12 (static configuration var that defines default
text size)
item is a textField (but could be something else)

function:

        // resize to container size ( - offest )
        // resize font if its a textField
        private function constrainToSize(item)
        {
            var offset:Number = 3

            // resize width first

            if (item.width >= cw - offset)
            {
                //if textfield, resize font

                var type = getQualifiedClassName(item)
                if (type == "flash.text::TextField")
                {
                    trace("itemIsText")

                    var formatSize:int = Config.defautltFontSize * (cw /
item.width)

                    var format:TextFormat = item.getTextFormat()
                    format.size = formatSize
                    item.setTextFormat( format);
                }

                item.width = cw - offset;
                trace("constrained w : "+newW)
            }


On Tue, Apr 6, 2010 at 19:06, Glen Pike <[email protected]> wrote:

> Hi,
>
>   I had to do something similar - loop down the size until it fits :(
>  Sorry, no joy here...
>
>   Glen
>
> mika wrote:
>
>> Hi,
>>
>> I am creating textfields in zones with differents width and heights. The
>> content of textfiels depends on user input.
>> I'd like to change the font size of the textfield so that the text is
>> fully
>> displayed (using wordwrap=true and autoSize)
>>
>> I could imagine a testing loop that decreases  textfield font until it has
>> appropriate size, but that sounds rather nasty.
>>
>> Anyone can think of a cleaner approach ? This is AS3
>>
>> Thanks
>> _______________________________________________
>> 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
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to