South.Africa.Roadtrip.2007-08_353Jodo-Milano.2008-09_035Nanbudo_WCh2006_076Slovenia2009-04_658Saaristoleiri 2009-08 34Kobe, Japan 2010-05-01Kuortti.2010-06-26Kuortti.2010-06-26Somero2002_02Helsinki2005-10-15_16_042Vesa-Rauttu-60v_1899Shiga, Japan 2010-04-18Pakkas03Pitkanen_076Saaristoleiri-Uto-2008_180Saaristoleiri-Uto-2008_177Oslo.Norway.2002.summer.034Kobe, Japan 2010-04-28Zoo2006-10-07_043italia2005-05_131Nanbudo_Norge2007-12_038italia2005-04_219norge5oslo_169
Flowers found on a hill

After a long training session with long sticks on a hill near Ljubljana, Slovenia, I saw these flowers on the way back.

TextField size according to its content

This example demonstrates the use of TextField.getRect() function.

package {
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.TextEvent;
    import flash.geom.Rectangle;
    import flash.text.AntiAliasType;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;

    [SWF( backgroundColor = '0x5B5B5B', frameRate = '33', width = '400', height = '200')]

    public class TextFieldBackground extends Sprite {

        private var format:TextFormat;
        private var field:TextField;
        private var background:Shape;

        public function TextFieldBackground() {

            background = new Shape();
            background.x = 10;
            background.y = 10;
            this.addChild(background);

            format = new TextFormat();
            format.font = "Verdana";
            format.color = 0x000000;
            format.bold = true;
            format.size = 12;
            format.align = TextFormatAlign.LEFT;

            field = new TextField();
            field.autoSize = TextFieldAutoSize.LEFT;
            field.antiAliasType = AntiAliasType.ADVANCED;
            field.defaultTextFormat = format;
            field.type = TextFieldType.INPUT;
            field.multiline = true;
            field.text = "Ichiban ni narukoto wa kesshite kantan dewanai.\nThe best never comes easy.";
            field.x = background.x;
            field.y = background.y;
            field.addEventListener(TextEvent.TEXT_INPUT, onTextChange);
            this.addChild(field);

            drawBackground();
        }

        private function drawBackground():void {
            var rect:Rectangle = field.getRect(this);

            var gra:Graphics = background.graphics;
            gra.clear();
            gra.beginFill(0xFFFFFF);
            gra.lineStyle(1, 0x000000);
            gra.drawRoundRect(0, 0, rect.width, rect.height, 6, 6);
        }

        private function onTextChange(evt:TextEvent):void {
            drawBackground();
        }
    }
}

TextFieldBackground.swf

Time: 16/04/2008 16:30

QR code for paazio.nanbudo.fi