Skip to main content
September 15, 2009
Question

newbie format problem

  • September 15, 2009
  • 2 replies
  • 870 views

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

This topic has been closed for replies.

2 replies

September 19, 2009

Hi Robin

Thanks for your response but I'm still having trouble. I'm lost on what I am doing wrong. I'm following the examples that Adobe has but it is still not working.

If you dont mind taking a look at my code, I'm going nuts over here!! Am I applying the textformat correctly? I can change everything just not the  JustificationRule.

Code://

private function initTest():void
        {
            var textContainer:Sprite = new Sprite()
            addChild(textContainer);

            var text:String ="すべての人間は、生まれながらにして自由であり、かつ、尊厳と権利とについて平等である。人間は、理性と良心とを授けられており、互いに同胞の精神をもって行動しなければならない。";
           
            var config:Configuration = new Configuration();
           
            var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
            textLayoutFormat.color = 0x000000;
              textLayoutFormat.fontFamily = "_JapaneseFont";
               textLayoutFormat.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
            textLayoutFormat.fontSize = 13;
            textLayoutFormat.kerning = Kerning.ON;
            textLayoutFormat.textAlign = TextAlign.LEFT;
            textLayoutFormat.justificationRule = JustificationRule.EAST_ASIAN;
           
            config.textFlowInitialFormat = textLayoutFormat;
           
            textFlow = new TextFlow(config);

            var p:ParagraphElement = new ParagraphElement();
            p.justificationRule = JustificationRule.EAST_ASIAN;
        
            var span:SpanElement = new SpanElement();
               span.text = getUnicodeText("Japanese");
               p.addChild(span);
           
            textFlow.addChild(p);
            textFlow.interactionManager = new SelectionManager();
            textFlow.flowComposer.addController(new ContainerController(this,350,350));
            textFlow.flowComposer.updateAllControllers();


        }

Regards

mugwart

September 20, 2009

I got it!

textLayoutFormat.blockProgression = "rl"

Thanks for the guidance Robin - led em to the right answer. I'm rather embarrassed it was so easy!

regards

mugwart

Adobe Employee
September 17, 2009

I think the problem may be with the "format" variable. You create it, and assign attributes to it, but it is not associated with any of the flow elements. I think you probably want to set these attributes directly one on of the flow elements, exactly as you are doing with the other attributes.

Hope this helps,

- robin