Sep 30, 2009 3:41 AM
TabElement Not Supported with TextLayout Framework
-
Like (0)
Hi
I am creating application using textLayout Framework with Flex 3(SDK 3.4).
I write a code like i have two SpanElements i.e. spanElement1 and spanelement2 ans one TabElement.
code like this:
// First Span--------------------------------
var paraElement:ParagraphElement = new ParagraphElement();
var spanElement1:SpanElement = new SpanElement();
spanElement1.text ="A";
paraElement.addChild(spanElement1);
// TabELement-------------------------------------------------
var tabElement:TabElement = new TabElement ();
paraElement.addChild(tabElement);
// Second Span--------------------------
var spanElement2:SpanElement = new SpanElement();
spanElement2.text ="B";
paraElement.addChild(spanElement2);
The output of above code is :----------------
A
B
What i want Output like-----------------------
A B
TabElement gives output same as the output of BreakElement
so how can use TabElement.
If anyone know the solution of above problem then please reply .
You also need to set tabStops. For example, paraElement.tabStops = "36 72".
By default in current player a tab without a tabStop results in a new line. Current thinking is that's a bug and player will add default tab stops.
Richard
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="paragraphFormat()">
<mx:Script>
<![CDATA[
import flashx.textLayout.container.DisplayObjectContainerController;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.ParagraphElement;
import flash.text.engine.TabAlignment;
import flashx.textLayout.formats.TabStopFormat;
import flashx.textLayout.formats.ParagraphFormat;
import flashx.textLayout.elements.TextFlow;
private var textContainer:Sprite = null;
public function paragraphFormat():void
{
textContainer = new Sprite();
var textFlow:TextFlow = new TextFlow();
var paraFormat:ParagraphFormat = new ParagraphFormat();
paraFormat.marginLeft = 15;
paraFormat.marginTop = 15;
paraFormat.marginRight = 15;
paraFormat.marginBottom = 15;
paraFormat.textIndent = 8;
var tabStop1:TabStopFormat = new TabStopFormat();
tabStop1.alignment = TabAlignment.CENTER;
tabStop1.position = 100;
paraFormat.tabStops = new Array(tabStop1);
textFlow.hostParagraphFormat = paraFormat;
var p:ParagraphElement = new ParagraphElement();
var span:SpanElement = new SpanElement();
span.text = "123\t\t\t456.";
//trace("text : "+ span.text);
span.fontSize = 32;
p.addChild(span);
textFlow.addChild(p);
textFlow.flowComposer.addController(new DisplayObjectContainerController(textContainer,400,500));
textFlow.flowComposer.updateAllContainers();
canvas.rawChildren.addChild(textContainer);
}
]]>
</mx:Script>
<mx:Canvas id="canvas" width="720" height="540" backgroundColor="#ECE9D8" verticalScrollPolicy="auto" borderColor="#000000" />
</mx:Application>
here is the code i have three "\t" in between the text .
now the output is like
123
456
please give anty solution how I add three or more tab in the text.
The problem here is that you have more tabs than tabstops, so the extra tabs take up the remaining space on the line.You can either just use one tab, with one tabstop set where you want it, or use multiple tabs with multiple tabstops.
I also notice you're using an older build. You can get a newer (improved!) build posted as part of the Flex Gumbo SDK.
Here's some newer code that would work:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="paragraphFormat()">
<mx:Script>
<![CDATA[
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.ParagraphElement;
import flash.text.engine.TabAlignment;
import flashx.textLayout.formats.TabStopFormat;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
private var textContainer:Sprite = null;
public function paragraphFormat():void
{
textContainer = new Sprite();
var textFlow:TextFlow = new TextFlow();
var paraFormat:TextLayoutFormat = new TextLayoutFormat();
paraFormat.paragraphStartIndent = 15;
paraFormat.paragraphSpaceBefore = 15;
paraFormat.paragraphEndIndent = 15;
paraFormat.paragraphSpaceAfter = 15;
paraFormat.textIndent = 8;
var tabStop1:TabStopFormat = new TabStopFormat();
tabStop1.alignment = TabAlignment.CENTER;
tabStop1.position = 100;
var tabStop2:TabStopFormat = new TabStopFormat();
tabStop2.alignment = TabAlignment.CENTER;
tabStop2.position = 200;
var tabStop3:TabStopFormat = new TabStopFormat();
tabStop3.alignment = TabAlignment.CENTER;
tabStop3.position = 300;
paraFormat.tabStops = [tabStop1, tabStop2, tabStop3];
textFlow.hostFormat = paraFormat;
var p:ParagraphElement = new ParagraphElement();
var span:SpanElement = new SpanElement();
span.text = "123\t\t\t456.";
//trace("text : "+ span.text);
span.fontSize = 32;
p.addChild(span);
textFlow.addChild(p);
textFlow.flowComposer.addController(new ContainerController(textContainer,400,500));
textFlow.flowComposer.updateAllControllers();
canvas.rawChildren.addChild(textContainer);
}
]]>
</mx:Script>
<mx:Canvas id="canvas" width="720" height="540" backgroundColor="#ECE9D8" verticalScrollPolicy="auto" borderColor="#000000" />
</mx:Application>
Hi Robin
Thanks for replying ,your answer is helpfull if there is Static Text,
I am importing text from the External XML and i dont know the number of Tabs and Position of Tab. then what can I do to add Tab Element in this Case.
Please Reply, If any Solution
Thanks
Well, you could just add a lot of tab stops; doesn't hurt to have too many. Or if for some reason you don't want to do that, you could programmatically count the tabs and add the correct number. I'm afraid I don't have a better solution.
- robin
I was maybe a little to quick there. We do recognise there's a problem with the tab stops. You ought to be able to set up default tab stops at intervals. But you can't do that today, so failing that, the best bet is to define enough for what you need.
Thanks,
- robin
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2011 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).