newbie format problem
Hey guys, hoping somebody could give me a hand. I'm trying to adapted the world languages example Adobe has online, to get it working with just Japanese text.
I can get the text working - just not the formating.
Could somebody please spot what I am doing wrong.
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.Font;
import flash.text.engine.FontLookup;
import flash.text.engine.Kerning;
import flash.text.engine.TextBaseline;
import flashx.textLayout.compose.StandardFlowComposer;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.conversion.TextFilter;
import flashx.textLayout.edit.SelectionManager;
import flashx.textLayout.elements.Configuration;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.Direction;
import flashx.textLayout.formats.JustificationRule;
import flashx.textLayout.formats.TextAlign;
import flashx.textLayout.formats.TextLayoutFormat;
public class FB4_textflow_japanese extends Sprite
{
private var fontPath:String = "Fonts/WorldClassFontPack.swf";
//TextFlow Elements
private var textFlow:TextFlow = new TextFlow();
private var format:TextLayoutFormat = new TextLayoutFormat();
private var paragraphElement:ParagraphElement = new ParagraphElement();
private var span:SpanElement = new SpanElement();
private var mainSelectionManager:SelectionManager = new SelectionManager();
private var controller:ContainerController;
//current language choice
private var currentLocale:String;
public function FB4_textflow_japanese()
{
loadFonts();
initText(); //init the TextFlow component
}
/* LOAD FONTS */
private function loadFonts():void
{
var request:URLRequest = new URLRequest(fontPath);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
loader.load(request);
}
/* SET FONTS */
private function fontLoaded (event:Event):void
{
var FontLibrary:Class = event.target.applicationDomain.getDefinition("WorldClassFontPack") as Class;
Font.registerFont(FontLibrary._EnglishFont);
Font.registerFont(FontLibrary._JapaneseFont);
}
/* INSTALL TEXT */
private function initText():void
{
var container:Sprite = new Sprite();
addChild(container);
span.text = getUnicodeText("Japanese");
span.dominantBaseline = TextBaseline.IDEOGRAPHIC_CENTER;
format.color = 0xFFFFFF;
format.fontFamily = "_JapaneseFont";
format.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
format.kerning = flash.text.engine.Kerning.ON;
format.lineHeight = "140%";
paragraphElement.direction = Direction.LTR;
paragraphElement.justificationRule = JustificationRule.EAST_ASIAN;
paragraphElement.textAlign = TextAlign.JUSTIFY;
paragraphElement.textAlignLast = TextAlign.START;
paragraphElement.addChild(span);
textFlow.addChild(paragraphElement);
textFlow.flowComposer = new StandardFlowComposer();
textFlow.flowComposer.addController(new ContainerController(container, stage.stageWidth, stage.stageHeight)); //target, width, height
textFlow.flowComposer.updateAllControllers();
}
private function getUnicodeText(locale:String):String
{
var result:String;
switch( locale ){
case "English":
result = "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.";
break;
case "Japanese":
result = "\u3059\u3079\u3066\u306E\u4EBA\u9593\u306F\u3001\u751F\u307E\u308C\u306A\u304C\u3089\u306B\u3057\u3066\u81EA\u7531\u3067\u3042\u308A\u3001\u304B\u3064\u3001\u5C0A\u53B3\u3068\u6A29\u5229\u3068\u306B\u3064\u3044\u3066\u5E73\u7B49\u3067\u3042\u308B\u3002\u4EBA\u9593\u306F\u3001\u7406\u6027\u3068\u826F\u5FC3\u3068\u3092\u6388\u3051\u3089\u308C\u3066\u304A\u308A\u3001\u4E92\u3044\u306B\u540C\u80DE\u306E\u7CBE\u795E\u3092\u3082\u3063\u3066\u884C\u52D5\u3057\u306A\u3051\u308C\u3070\u306A\u3089\u306A\u3044\u3002";
break;
}
return result;
}
}
}
Regards
mugwart
