TLF相關資料

1\(轉)http://blog.csdn.net/hu36978/article/details/5796165html

TFLweb

通常先建立TextFlow  經過控制flowComposer屬性來控制文本容器app

例如:composer

 

flow.flowComposer.addController(thisController);字體

文本容器是:ui

 

var thisController:ContainerController=new ContainerController(thisContainer,textPixelWidth, slatHeight);this

thisController須要添加進顯示列表url

this.addChild(thisController)spa

 

 刷新全部的文本容器.net

flow.flowComposer.updateAllControllers();

(注意,這樣的文本是鏈接起來的,但他們卻在不一樣的容器(Sprite)中)

 

 

 

建立TextFlow 有兩種方法:

1@

 flow = new TextFlow()

 

@2

flow=TextConverter.importToFlow(markup,TextConverter.TEXT_FIELD_HTML_FORMAT),  //html應用的比較多

 

flow=TextConverter.importToFlow(markup,TextConverter.TEXT_LAYOUT_FORMAT);

 

flow=TextConverter.importToFlow(markup,TextConverter.PLAIN_TEXT_FORMAT);

 

 

 

format的設置:

var format1:TextLayoutFormat = new TextLayoutFormat();

format1.color = 0x660000;

format1.fontFamily = "Arial, Helvetica, _sans";

format1.fontSize = 14;

format1.paragraphSpaceBefore=0;

format1.paragraphSpaceAfter=20;

var format2:TextLayoutFormat = new TextLayoutFormat();

format2.color = 0x990000;

format2.fontSize = 16;

format2.fontWeight = FontWeight.BOLD;

 

 

 

 

 

 

字體大小以及間距的設置:

 

flow.fontSize = fontSize;

flow.lineHeight = lineHeight;

flow.paddingTop = (flow.lineHeight - flow.fontSize)/2;

flow.paddingLeft = paddingLeft;

flow.paddingRight = paddingRight;

 

flow.columnCount=2; //列數 也就是默認的文本框TLF數

flow.columnGap=30;//兩列間的距離

 

//format

flow.hostFormat = format1;

.

 

TEXT_FIELD_HTML_FORMAT的使用< TextConverter? 幫助文檔裏有講解>

可使用<a>以及<img> (圖文混排)等的使用

 

 

flashx.textLayout.elements?包裏的類都是對文本進行處排版的一些類

 

ParagraphElement類能夠添加進TextFLow 而其餘的例如SpanElement則添加進ParagraphElement

對應的html是的<TextFlow> <p><span ></span></p> </TextFlow>

 

flow.addChild(ParagraphElement實例)

 

paragraphElement.addCHild(SpanElement)實例

LinkElement也能夠添加進paragraphElement

paragraphElement.addChild(LinkElement)

LinkElement就是連接 <a href=」」>

 

var link:LinkElement = new LinkElement();

 

link.href="http://www.flashandmath.com/flashcs5/textcols";

 

link.target="_self";

 

link.linkNormalFormat={color: 0x0000CC,textDecoration: "underline"};

 

link.linkActiveFormat={color: 0x0000CC,textDecoration: "underline"};

 

link.linkHoverFormat={color: 0xCC0000,textDecoration: "underline"};

 

 

var linkspan:SpanElement = new SpanElement();

 

linkspan.text="Multicolumn Text on the Fly with AS3 Flash CS5";

 

link.addChild(linkspan);

 

 

elements包裏類 使用 addChild 就至關於 <>嵌套

 

如上面 的link 和span 就是html的 <a href ="http://www.flashandmath.com/flashcs5/textcols"><span> Multicolumn Text on the Fly with AS3 Flash CS5</span></a>

 

 

使用外部的文件txt或者xnl均可以

下面是txt格式的:

 

將文本輸出外部文件中 首先要保存flow裏面的字符串

 

Txt格式:

var utString:String=TextConverter.export(flow,TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String;

xml 格式

 

var testxml:XML=TextConverter.export(flow,TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.XML_TYPE) as XML;

 

 

在用filereference保存到本地:

var file:FileReference= new FileReference()

//file.save(outString,"text.txt");  txt格式

file.save(testxml,"my.xml");、、xml格式

 

 

加載外部上述文件格式的文本:

用 URLLoader加載外部文件而且保存在變量fileContent中

 

在使用 

flow=TextConverter.importToFlow(fileContent,TextConverter.TEXT_LAYOUT_FORMAT);

    flow.flowComposer.addController(new ContainerController(container, 570, 370));

    flow.flowComposer.updateAllControllers();

 

 

這樣外部文件就保存在flow的ContainerController裏了

 

注意引入外部文件時 ,即 帶有<TextFlow> 標籤的使用

TextConverter.TEXT_LAYOUT_FORMAT類型

帶html如,<img>的通常使用TextConverter .TEXT_FIELD_HTML_FORMAT

根據習慣內部的都有HTML 外部的都用TEXT_LAYOUT_FORMAT類型

 

 

Txt格式文件以下:

<TextFlow color="#000000" columnCount="2" columnGap="30" columnWidth="250" fontSize="14" lineBreak="toFit" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" paragraphSpaceAfter="20" paragraphSpaceBefore="0" verticalAlign="top" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><p color="#990000" fontSize="16" fontWeight="bold"><span>Loading TLF Text at Runtime with AS3 in Flash CS5</span></p><p><span>The new TLF text features available in Flash CS5 are great for creating advanced text effects. Especially, if you can load text dynamically at runtime. If you use predefined text, you can always work with the Classic Text and MovieClips.</span></p><p color="#990000" fontSize="16" fontWeight="bold"><span>TLF Markup and Loading</span></p><p><span>In this tutorial, we show how to write an markup file that contains TLF text and formatting, load the file at runtime, and create a TLF TextFlow object containing loaded text. Since the documentation for TLF markup is a bit hard to find, we created a fla file, getmarkup.fla, that generates a correctly structured TLF markup file. See this tutorial's web page and getmarkup.fla file in the zip package for explanations. Once we have a correctly structured markup file, we can easily edit and customize it. Then we can load the text file at runtime and use the TextConverter class to import the information contained in the text file (text, layout, and formatting) into our instance of the TextFlow class. In this tutorial we use only some of the many formatting features of the TextFlow class. There are many more. You can find them in the AS3 Flash CS5 online documentation. See out tutorial: </span><a href="http://www.flashandmath.com/flashcs5/textcols" target="_self"><linkActiveFormat><TextLayoutFormat color="#0000cc" textDecoration="underline"/></linkActiveFormat><linkHoverFormat><TextLayoutFormat color="#cc0000" textDecoration="underline"/></linkHoverFormat><linkNormalFormat><TextLayoutFormat color="#0000cc" textDecoration="underline"/></linkNormalFormat><span>Multicolumn Text on the Fly with AS3 Flash CS5</span></a><span> for more examples of how to use these TextLayout classes.</span></p></TextFlow>

 

2\(轉)http://hi.baidu.com/iscriptdada/item/23796aee0b06311b570f1d17

 使用方法:

var _sprite:Sprite = new Sprite();

var _txFormat:TextLayoutFormat = new TextLayoutFormat(); // 默認樣式

var html:String = "";

var _tf:TextFlow = TextConverter.importToFlow(html, TextConverter.TEXT_FIELD_HTML_FORMAT); //導入html,生成textflow

var _em:EditManager = new EditManager(new UndoManager()); //編輯選擇、樣式設置

_tf.interactionManager = _em;

_em.focusedSelectionFormat = new SelectionFormat(0xa8c6ee, 1.0, BlendMode.NORMAL, 0xa8c6ee, 1.0, BlendMode.NORMAL, 0); 

_em.inactiveSelectionFormat = new SelectionFormat(0xa8c6ee, 1.0, BlendMode.NORMAL, 0xa8c6ee, 1.0, BlendMode.NORMAL, 0);

_em.unfocusedSelectionFormat = new SelectionFormat(0xe8e8e8, 1.0, BlendMode.NORMAL, 0xe8e8e8, 1.0, BlendMode.NORMAL, 0);

addChild(_sprite);

tf.format = _txFormat;

var _container:ContainerController = new ContainerController(_sprite,width, height); //顯示容器控制器

_tf.flowComposer.addController(_container);           

_tf.addEventListener(SelectionEvent.SELECTION_CHANGE, selectionChangeListener, false, 0, true);

_tf.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE, graphicStatusChangeEvent, false, 0, true);

_tf.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler, false, 0, true);

_tf.addEventListener(FlowOperationEvent.FLOW_OPERATION_COMPLETE, change); 

一、 設置textflow失去焦點時的選中狀態

var selectionManager:ISelectionManager = textFlow.interactionManager;//當選擇部分不在活動窗口中時,用於繪製選擇的 SelectionFormat 對象。

selectionManager.inactiveSelectionFormat = new SelectionFormat(0xa8c6ee, 1.0, BlendMode.NORMAL, 0xa8c6ee, 1.0, BlendMode.NORMAL, 0); //當選擇部分不在焦點容器內可是位於活動窗口中時,用於繪製選擇的 SelectionFormat 對象。

selectionManager.unfocusedSelectionFormat = new SelectionFormat(0xe8e8e8, 1.0, BlendMode.NORMAL, 0xe8e8e8, 1.0, BlendMode.NORMAL, 0); 

二、經過TextConverter.importToFlow(html, TextConverter.TEXT_FIELD_HTML_FORMAT) 獲得的textflow,不能改變color這樣的屬性,若是要改變這些屬性,只能經過導入純文本,而後設置樣式。  

三、讓光標定位到文本最後

textflow.interactionManager.selectRange(textField.tf.getText().length,textField.tf.getText().length);

textflow.interactionManager.setFocus(); 

四、若顯示區域小於文本總長度,經過滾動的方式,讓顯示區域顯示對應的文字。_container.verticalScrollPosition 屬性改變垂直滾動位置, 

五、TextLayoutFormat  lineHeight屬性:

表示行高合法值爲 -720 到 720 範圍內的數字。

合法值爲 -1000% 到 1000% 範圍內的百分比數字。

合法值包括 FormatValue.INHERIT。默認值未定義,指示未設置。若是在層疊期間未定義,則此屬性將從一個祖代繼承值。若是沒有祖代設置了此屬性,則其值爲 120%。  

六、TextFlow 深拷貝

var copiedTextFlow:TextFlow = textFlow.deepCopy() as TextFlow;

var someOtherTextFlow:TextFlow = new TextFlow();

someOtherTextFlow.replaceChildren(0, someOtherTextFlow.numChildren);

while (copiedTextFlow.numChildren){

// in order builds this is a little more complicated (psuedo code here you will have to debug it)//

var child = copiedTextFlow.getChildAtIndex(0);

// copiedTextFlow.removeChild(child);

// someOtherTextFlow.addChild(child)    

someOtherTextFlow.addChild(copiedTextFlow.getChildAtIndex(0));

七、獲得textline的方式

var flow:TextFlow = tArea.textFlow;

var composer:StandardFlowComposer = (flow.flowComposer as StandardFlowComposer); 

var tfline:TextFlowLine = composer.getLineAt(composer.numLines-1);

var line:TextLine = tfline.getTextLine();  

var factory:StringTextLineFactory = new StringTextLineFactory();

factory.compositionBounds = rect;

factory.createTextLines( useTextLines );

function useTextLines( line:DisplayObject ):void { }
var factory:TextFlowTextLineFactory = new TextFlowTextLineFactory();

factory.compositionBounds = new Rectangle(0,0,w,h);

factory.createTextLines(callback,textFlow);

function callback(tl:TextLine):void { }    

八、經過導入htmltext生成textflow的方式,設置TextLayoutFormat屬性無效。

由於直接改變這些屬性也是設置html標籤,不過是套在最外層,只有經過選中某部分,而後經過EditManager來改變纔有效。

var pa:TextLayoutFormat = new TextLayoutFormat();

pa.color = 0x0000ff;

_em.selectAll();

_em.applyLeafFormat( pa, _em.getSelectionState() ); 

九、如何在縮小放大時自適應行高? 

十、如何複製圖片?

 

3\(轉)http://zhidao.baidu.com/link?url=MInLapnqOpkw5evcTJsw3AIxa3HfnsuByeuEfoul2V_D749bSdFfdLQaBhLHy7P7MR3yRcy718WosfvtvyhysK

TLFTextField與TextField方法相似,區別就是在於TLFTextField能使用flashx包中的包含的TLF類的方法和屬性。所以在對齊方式上,仍然採起了autoSize屬性。控制文本字段的自動大小調整和對齊。TextFieldAutoSize 常數的可接受值爲 TextFieldAutoSize.NONE(默認值)、TextFieldAutoSize.LEFT、TextFieldAutoSize.RIGHT 和 TextFieldAutoSize.CENTER。

若是 autoSize 設置爲 TextFieldAutoSize.NONE(默認值),則不會進行調整。

若是 autoSize 設置爲 TextFieldAutoSize.LEFT,會將文本視爲左對齊文本,這意味着該文本字段的左邊距保持固定,在右邊可調整單個文本字段行。若是文本中包括換行符(例如 "\n" 或 "\r"),則會另外調整底邊來適合文本的下一行。若是 wordWrap 也設置爲 true,則僅調整文本字段的底邊,而右邊距保持固定。

若是 autoSize 設置爲 TextFieldAutoSize.RIGHT,會將文本視爲右對齊文本,這意味着該文本字段的右邊距保持固定,可在左邊調整單個文本字段行。若是文本中包括換行符(例如 "\n" or "\r")),則會另外調整底邊來適合文本的下一行。若是 wordWrap 也設置爲 true,則僅調整文本字段的底邊,而左邊距保持固定。

若是 autoSize 設置爲 TextFieldAutoSize.CENTER,會將文本視爲居中對齊文本,這意味着對單個文本字段行的調整將使其在左右邊距間均衡分佈。若是文本中包括換行符(例如 "\n" 或 "\r"),則會另外調整底邊來適合文本的下一行。若是 wordWrap 也設置爲 true,則僅調整文本字段的底邊,而左右邊距保持固定。

相關文章
相關標籤/搜索