There are a lot of nice text features in the new flash text layout framework but obviosly there is still one important feature missing: Hyphenation. Until today, there is no native hyphenation support in the flashplayer. I decided to fill this gap by porting the Hyphenator.js library by Mathias Nater to ActionScript. In this post I’ll demonstrate text hyphenation in flash.
Here you see the hyphenation in action. You can choose one of the currently supported languages and resize the text field to see the hyphenation changes.
The usage is pretty simple. To hyphenate the text of a textfield you only have to call the hyphenateTextField() function and provide the text language and the textfield instance as parameters.
// creating a new textfield first var tf:TextField = new TextField(); tf.multiline = true; tf.width = 400; tf.text = 'long text that goes over multiple lines'; addChild(tf); // let's hyphenate Hyphenator.hyphenateTextField('en', tf);
Download & License
Update (May 20, 2010): the hereby presented algorithm does only work for textfields without stylesheets. I’ll try to extend it in the next weeks.