Search code examples
actionscript-3actionscripttextoutline

Set text outlining / border in Actionscript 3.0


How can I set the properties for the text outline / border for each character in a line of text in AS3 ?


Solution

  • I don't think you can. What you can do is use a blur filter to mimic the appearance of an outline. Just paste this into an empty AS3 movie:

    var txt:TextField = new TextField();
    this.addChild(txt);
    txt.appendText('Lorem ipsum');
    txt.autoSize = TextFieldAutoSize.LEFT;
    txt.antiAliasType = flash.text.AntiAliasType.NORMAL;
    txt.selectable = false;
    
    var txtFormat:TextFormat = new TextFormat();
    txtFormat.size = 40;
    txtFormat.font = 'Helvetica';
    txt.setTextFormat(txtFormat);
    txt.defaultTextFormat = txtFormat;
    
    var outline:GlowFilter = new GlowFilter();
    outline.blurX = outline.blurY = 1;
    outline.color = 0xFF0000;
    outline.quality = BitmapFilterQuality.HIGH;
    outline.strength = 100;
    
    var filterArray:Array = new Array();
    filterArray.push(outline);
    txt.filters = filterArray;
    

    Try playing with the strength, blurX, blurY and quality properties, in order to obtain different appearances. I think that's about the closest you can get to a text outline.

    PS: font embedding would greatly improve the quality of the effect, as well as making the antialias work properly.