TLF 使用详解!!

TFL

 

 

 

一般先创建TextFlow  通过控制flowComposer属性来控制文本容器

例如:

 

flow.flowComposer.addController(thisController);

文本容器是:

 

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

thisController需要添加进显示列表

this.addChild(thisController)

 

 刷新所有的文本容器

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();

 

 

这样外部文件就保存在flowContainerController里了

 

注意引入外部文件时 ,即 带有<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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值