zoukankan      html  css  js  c++  java
  • TLF相关资料

    1(转)http://blog.csdn.net/hu36978/article/details/5796165

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

    这样外部文件就保存在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); 

    1、 设置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); 

    2、通过TextConverter.importToFlow(html, TextConverter.TEXT_FIELD_HTML_FORMAT) 得到的textflow,不能改变color这样的属性,如果要改变这些属性,只能通过导入纯文本,然后设置样式。  

    3、让光标定位到文本最后

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

    textflow.interactionManager.setFocus(); 

    4、若显示区域小于文本总长度,通过滚动的方式,让显示区域显示对应的文字。_container.verticalScrollPosition 属性改变垂直滚动位置, 

    5、TextLayoutFormat  lineHeight属性:

    表示行高合法值为 -720 到 720 范围内的数字。

    合法值为 -1000% 到 1000% 范围内的百分比数字。

    合法值包括 FormatValue.INHERIT。默认值未定义,指示未设置。如果在层叠期间未定义,则此属性将从一个祖代继承值。如果没有祖代设置了此属性,则其值为 120%。  

    6、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));

    7、得到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 { }    

    8、通过导入htmltext生成textflow的方式,设置TextLayoutFormat属性无效。

    因为直接改变这些属性也是设置html标签,不过是套在最外层,只有通过选中某部分,然后通过EditManager来改变才有效。

    var pa:TextLayoutFormat = new TextLayoutFormat();

    pa.color = 0x0000ff;

    _em.selectAll();

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

    9、如何在缩小放大时自适应行高? 

    10、如何复制图片?

    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,会将文本视为左对齐文本,这意味着该文本字段的左边距保持固定,在右边可调整单个文本字段行。如果文本中包括换行符(例如 " " 或 " "),则会另外调整底边来适合文本的下一行。如果 wordWrap 也设置为 true,则仅调整文本字段的底边,而右边距保持固定。

    如果 autoSize 设置为 TextFieldAutoSize.RIGHT,会将文本视为右对齐文本,这意味着该文本字段的右边距保持固定,可在左边调整单个文本字段行。如果文本中包括换行符(例如 " " or " ")),则会另外调整底边来适合文本的下一行。如果 wordWrap 也设置为 true,则仅调整文本字段的底边,而左边距保持固定。

    如果 autoSize 设置为 TextFieldAutoSize.CENTER,会将文本视为居中对齐文本,这意味着对单个文本字段行的调整将使其在左右边距间均衡分布。如果文本中包括换行符(例如 " " 或 " "),则会另外调整底边来适合文本的下一行。如果 wordWrap 也设置为 true,则仅调整文本字段的底边,而左右边距保持固定。

  • 相关阅读:
    java数的相加
    读大道至简第二章有感
    读大道至简第一章有感
    课题的跨专业组队
    返回一个整数数组中最大子数组的和。
    《构建之法》阅读笔记02
    单元测试(2)
    软件工程个人作业03
    单元测试
    团队
  • 原文地址:https://www.cnblogs.com/xbglbc/p/3662076.html
Copyright © 2011-2022 走看看