Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text alignment question

Guest
Feb 26, 2013 Feb 26, 2013

Hi guys

Just wondering if there is a way to keep two sentences in one string on the same line, but one aligned left, the other right using html or TLF?

So...

left margin>FIRST SENTENCE             SECOND SENTENCE<right margin

The string is being injected into a textflow, so it would need to work with either TEXT_FIELD_HTML_FORMAT or TEXT_LAYOUT_FORMAT.

I've imported css via a formatResolver, and have a class that colors and aligns the font. The color works, but aligning it does nothing.

Thanks for taking a look.

TOPICS
ActionScript
718
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2013 Feb 26, 2013

you can use text-align in your css.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 26, 2013

It doesn't do anything in span - but it does in <p> (or should I say - I'm doing something wrong).

text-align: right; (and I've tried textAlign: right;)

fontSize: 40;

color: 0xff00;

margin-left: 100px;

The font size and color works, so everything is communicating ok.

<p> does me no good, as I need the two sentences on the same line.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 26, 2013 Feb 26, 2013

What if you fake this? Put two TextFields on top of each other with the same width and height then align the first one left and the second one right. I tried to play with aligning it properly in a single TextField but it seems impossible without doing math and just inserting spaces procedurely.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2013 Feb 26, 2013

you (or formatResolver) are doing something wrong.  you should be doing something like:

var cssLoader:URLLoader = new URLLoader();

var cssRequest:URLRequest = new URLRequest("yourcss.css");

var css:StyleSheet = new StyleSheet();

       

cssLoader.load(cssRequest);

cssLoader.addEventListener(Event.COMPLETE,onCSSComplete);

       

function onCSSComplete(e:Event):void {

css.parseCSS(cssLoader.data);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 26, 2013

Thanks for your help guys.

@Nabren - it's one single long string that I'm sending into a textFlow, which gets split into three columns per page - ascending alpabetically from top to bottom of each column, then onto the next page (created in a loop). The flowComposer seems to take care of the splitting up of the string really well, so I'm unsure how to inject textFields into the logic.

@kGlad - I'm not sure what I'm doing wrong - the AS3CSSSample.as (untouched by me) doesn't work on certain things in spans either - the italics don't work

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 26, 2013
LATEST

Forgot to mention it's for an AIR desktop app.  Here's the guts of the code from AS3CSSSample.as - some of the tags don't seem to work...

[Embed(source="SimpleCSS.css",mimeType="application/octet-stream")]

        private var SimpleCSS : Class;

       

        //private var styleSheet:StyleSheet = new StyleSheet;

        private var styleSheet:StyleSheet = new TLFStyleSheet;

           

            // parse a styleSheet

        private var cssByteArray:ByteArray = new SimpleCSS();

        private var cssText:String = cssByteArray.readMultiByte(cssByteArray.length,"utf-8");

          flow = new TextFlow();

 

            flow.flowComposer = new StandardFlowComposer();           

           

            styleSheet.parseCSS(cssText);

            flow.formatResolver = new CSSFormatResolver(styleSheet);

var simpleText:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>"

            + "<p styleName='center'><span>There are many </span><span styleName='italic'>such lime-kilns in that tract of country, for the purpose of burning the white marble which composes a large part of the substance of the hills. Some of them, built years ago, and long deserted, with weeds growing in the vacant round of the interior, which is open to the sky, and grass and wild-flowers rooting themselves into the chinks of the stones, look already like relics of antiquity, and may yet be overspread with the lichens of centuries to come. Others, where the lime-burner still feeds his daily and nightlong fire, afford points of interest to the wanderer among the hills, who seats himself on a log of wood or a fragment of marble, to hold a chat with the solitary man. It is a lonesome, and, when the character is inclined to thought, may be an intensely thoughtful occupation; as it proved in the case of Ethan Brand, who had mused to such strange purpose, in days gone by, while the fire in this very kiln was burning.</span></p>"

            + "<p><span>The man who now watched the </span><span id='bold'>fire</span><span> was of a </span><span typeName='foo'>different</span><span> order, and troubled himself with no thoughts save the very few that were requisite to his business. At frequent intervals, he flung back the clashing weight of the iron door, and, turning his face from the insufferable glare, thrust in huge logs of oak, or stirred the immense brands with a long pole. Within the furnace were seen the curling and riotous flames, and the burning marble, almost molten with the intensity of heat; while without, the reflection of the fire quivered on the dark intricacy of the surrounding forest, and showed in the foreground a bright and ruddy little picture of the hut, the spring beside its door, the athletic and coal-begrimed figure of the lime-burner, and the half-frightened child, shrinking into the protection of his father's shadow. And when again the iron door was closed, then reappeared the tender light of the half-full moon, which vainly strove to trace out the indistinct shapes of the neighboring mountains; and, in the upper sky, there was a flitting congregation of clouds, still faintly tinged with the rosy sunset, though thus far down into the valley the sunshine had vanished long and long ago.</span></p>"

            + "</TextFlow>";

var textFlow:TextFlow = TextConverter.importToFlow(simpleText, TextConverter.TEXT_LAYOUT_FORMAT);

            // wipe out the default inherits - format take precendence over CSS - this simplifies the example

            textFlow.format = null;

            // attach a format resolver

            textFlow.formatResolver = new CSSFormatResolver(styleSheet);

            // set it into the editor

            textFlow.flowComposer.addController(new ContainerController(this,500,500));

            textFlow.flowComposer.updateAllControllers();

            flow.styleSheet = styleSheet;

            // attach a format resolver

            flow.formatResolver = new formatResolver(styleSheet);

            // set it into the editor

            textFlow.flowComposer.addController(new ContainerController(this,500,500));

            textFlow.flowComposer.updateAllControllers();

/**

    ADOBE SYSTEMS INCORPORATED

    Copyright 2008 Adobe Systems Incorporated

    All Rights Reserved.

    NOTICE:  Adobe permits you to use, modify, and distribute this file

    in accordance with the terms of the Adobe license agreement

    accompanying it.  If you have received this file from a source

    other than Adobe, then your use, modification, or distribution

    of it requires the prior written permission of Adobe.

*/

span

{

    fontSize:        18;

}

TextFlow

{

    columnCount:            2;

    textIndent:             15;

    paragraphSpaceAfter:    15;

    paddingTop:             4;

    paddingLeft:            4;

}

foo

{

    fontSize:        18;

    color:            0xff00;

}

.italic

{

    #fontStyle:        italic;

    #color:            0xff;

    #fontFamily:    Helvetica;

}

.center

{

    textAlign:        center;

}

#bold

{

    fontWeight:        bold;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines