Rendering text in AS3 using FTE (Flash Text Engine)

Since I think devlopers’ attention will focus on mobile game developement during these days, let’s see a feature that will let you use fonts in a way that will successfully adapt across devices, as introduced in the Authoring mobile Flash content for multiple screen sizes guide.

FTE (Flash Text Engine)

The FTE provides low-level support for sophisticated control of text metrics, formatting, and bidirectional text. It was primarily designed as a foundation for developers to create text-handling components, but in this simple example I’ll use it like a normal text field to see if I can improve its readability.

This example is intended to be ran on Flash Player 10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package {
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.engine.*;
	public class fte extends Sprite {
		public function fte():void {
			// FTE TEXT
			var font_description:FontDescription = new FontDescription();
			font_description.fontName="Verdana";
			font_description.fontWeight=FontWeight.BOLD;
			font_description.fontPosture=FontPosture.ITALIC;
			font_description.renderingMode=RenderingMode.CFF;
			font_description.locked=true;
			var element_format:ElementFormat=new ElementFormat(font_description);
			element_format.fontSize=40;
			element_format.kerning=Kerning.ON;
			element_format.color=0x000000;
			element_format.alpha=1;
			var text_element:TextElement=new TextElement("Hello Flash World",element_format);
			var text_block:TextBlock = new TextBlock();
			text_block.content=text_element;
			var text_line:TextLine=text_block.createTextLine(null,500);
			text_line.x=20;
			text_line.y=40;
			addChild(text_line);
			// NORMAL TEXT
			var text_field:TextField=new TextField();
			var text_format:TextFormat = new TextFormat();
			text_format.color=0x000000;
			text_format.size=40;
			text_format.bold=true;
			text_format.font="Verdana";
			text_format.italic=true;
			text_field.x=18;
			text_field.y=30;
			text_field.width=460;
			text_field.height=60;
			text_field.text="Hello Flash World";
			text_field.setTextFormat(text_format);
			addChild(text_field);
		}
	}
}

Line 5: importing the required library

Lines 9-14: using FontDescription class to represent the font. As you can see in the official docs, locking the font (line 14) and setting the rendering mode to CFF (line 13) shoud make the text more legible, especially at small sizes

Lines 15-19: using ElementFormat class to set formatting information. As described in the docs the only interesting feature I did not use was the baseline alignment. Turning off the kerning (line 17) should improve readability

Line 20: using TextElement class to declare the string of formatted text I am about to display. No fancy features here according to the docs

Lines 21-22: TextBlock class is the renderer itself, but it’s more about formatting and management than rendering, according to the docs

Lines 23-25: using TextLine class to display the content. According to the docs, it just has a lot of read only properties.

Lines 28-40: doing the same thing with old text fields.

And this is the result:

The upper line is made using FTE, the lower one with normal text fields.

I have to say I don’t see noticeable improvements, anyway it will introduce you into FTE world.

Download the source code.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 5 comments

  1. Tink

    on July 22, 2010 at 1:57 pm

    “The upper line is made using FTE, the lower one with normal text fields.
    I have to say I don’t see noticeable improvements, anyway it will introduce you into FTE world.”

    You would if you were adding images, creating complex text layouts, using rtl or ttb text, or complex styling.

    … but on the flip side you would see performance degrade.

  2. ramin

    on July 22, 2010 at 3:35 pm

    Well,

    This is all nice and the new APIs provide more functionality. The fact of the matter is that Adobe cannot provide, both a simple and complete solution. In our company, we started to use the new Engine on an application supporting 11 languages, CSS, dynamic fonts, etc. All these were doable with the old TextField but not perfect. With the new Engine, even though more powerful, managing text and specially supporting CSS and is not trivial. Hopefully one day we will get an Engine that provides an Engine working with standard CSS and easier APIs.

  3. diiiimaaaa

    on July 22, 2010 at 4:37 pm

    To see difference between FTE and old text, use smaller font size and you will see that FTE looks much better.

  4. Samuel Jonasson

    on July 22, 2010 at 11:28 pm

    Not having to embed Chinese glyphs to get to do simple alpha or get anti aliased text is a biggie. So anyone doing a multilingual site that requires huge character sets should investigate.

  5. Weekly Shared Items – 26. July, 2010 | TOXIN LABS - weblog of a german design student from wuerzburg

    on July 26, 2010 at 8:06 am

    [...] Rendering text in AS3 using FTE (Flash Text Engine) [...]