Flash AS3, is text anti-aliasing controlled by code?

Ghost9 picture Ghost9 · Dec 6, 2010 · Viewed 10.4k times · Source

Is text anti-aliasing controlled by code, or is it embedded? What I want to do is take a swf file that someone else has made, find all of the text in the swf file and change all of the anti-aliasing modes from animation to readability. Does it work that way in as3? I honestly haven't tried any anti-aliasing in code yet.

Answer

momo picture momo · Dec 6, 2010

you can set the antiAliasType of a textfield to 'advanced', which gives you fine control over sharpness and thickness. however, the fonts must be embedded (inclusive: the textfield must have embedFonts set to true, the TextFormat objects must have font properties exactly equal to the fontName of the embedded font, and the fonts must be already compiled). so technically 'is it possible?' - yes. is it likely to work the way you want it to? no, unless you plan on working with a swiff that you know is using embedded fonts already. then you'll need to grab all the textfields from the loaded swiff (you could use something like this: http://upshots.org/?p=107, then use array.filter to get back only TextField objects), then apply your logic.

EDIT: adding code sample

// assuming you're using the DisplayList class linked above
var request:URLRequest = new URLRequest("textfields.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
loader.load(request);

function completeHandler(event:Event):void{

    var content:DisplayObjectContainer = event.target.loader.content as DisplayObjectContainer;
    addChild(content);

    var children:Array = new DisplayList(content);
    children = children.filter(function(item:Object, index:int, array:Array):Boolean {
        return item is TextField;
    });
    children.forEach(function(item:Object, index:int, array:Array):void {
        var textfield:TextField = item as TextField;
        textfield.antiAliasType = AntiAliasType.ADVANCED;
        textfield.sharpness = 100;
        textfield.thickness = 100;
    });
}

just ran a quick test - works as described.