包 | flashx.textLayout.elements |
类 | public final class ParagraphElement |
继承 | ParagraphElement ParagraphFormattedElement FlowGroupElement FlowElement Object |
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
默认 MXML 属性mxmlChildren
相关 API 元素
公共方法
方法 | 由以下参数定义 | ||
---|---|---|---|
构造函数 - 表示文本流中的一个段落。 | ParagraphElement | ||
追加一个 FlowElement 子对象。 | FlowGroupElement | ||
在指定索引位置添加一个 FlowElement 子对象。 | FlowGroupElement | ||
从该 FlowElement 对象清除 styleProp 参数指定的样式。 | FlowElement | ||
生成此 FlowElement 对象的深层副本,包括任何子对象,在两个指定的字符位置之间复制内容,并将该副本作为 FlowElement 对象返回。 | FlowElement | ||
将此元素的 userStyles 与其它元素的 userStyles 比较。 | FlowElement | ||
对于给定的相对文本位置,查找包含该相对位置的第一个 FlowElement 子对象的索引。 | FlowGroupElement | ||
对于给定的相对文本位置,查找包含该位置的叶元素。 | FlowGroupElement | ||
从提供的位置向前扫描,以找到文本中下一个原子的位置并返回索引。 | ParagraphElement | ||
返回文本中下一个单词边界的索引。 | ParagraphElement | ||
从提供的位置向后扫描,以找到文本中上一个原子的位置并返回索引。 | ParagraphElement | ||
返回文本中上一个单词边界的索引。 | ParagraphElement | ||
返回该元素在文本流中的起始位置(绝对索引)。 | FlowElement | ||
返回相对于该 FlowElement 对象的指定位置的字符。 | FlowElement | ||
返回相对于该 FlowElement 对象的指定位置的字符代码。 | FlowElement | ||
返回位于指定索引的 FlowElement 子对象。 | FlowGroupElement | ||
在子对象中搜索指定的 FlowElement 对象,并返回其索引位置。 | FlowGroupElement | ||
返回该元素相对于祖代元素的起始位置。 | FlowElement | ||
返回该组的第一个 FlowLeafElement 子项。 | FlowGroupElement | ||
返回该组的最后一个 FlowLeafElement 子项。 | FlowGroupElement | ||
返回该段落之后的段落,如果不再有段落则返回 null。 | ParagraphElement | ||
返回文本流层次结构中的下一个 FlowElement 同级对象。 | FlowElement | ||
返回与该元素关联的 ParagraphElement 对象。 | FlowElement | ||
返回该段落之前的段落,如果该段落是 TextFlow 中的第一个段落,则返回 null。 | ParagraphElement | ||
返回文本流层次结构中的上一个 FlowElement 同级对象。 | FlowElement | ||
返回由 styleProp 参数指定的样式值,该参数指定样式名称,可以包括任何用户样式名称。 | FlowElement | ||
[覆盖] | FlowGroupElement | ||
沿文本流层次结构向上移动,返回该元素的 TextFlow 根对象。 | FlowElement | ||
表示对象是否已经定义了指定的属性。 | Object | ||
创建实现对象且初始化在 MXML 标签上指定的所有组件属性后针对 MXML 对象进行调用。 | FlowElement | ||
表示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | ||
表示指定的属性是否存在、是否可枚举。 | Object | ||
从组中删除指定的 FlowElement 子对象。 | FlowGroupElement | ||
删除位于指定索引位置的 FlowElement 子对象。 | FlowGroupElement | ||
以指定的新元素替换组中的子元素。 | FlowGroupElement | ||
设置循环操作动态属性的可用性。 | Object | ||
将 styleProp 参数指定的样式设置为 newValue 参数指定的值。 | FlowElement | ||
生成此 FlowElement 对象的副本,复制两个指定的字符位置之间的内容。 | FlowElement | ||
在 childIndex 参数指定的位置拆分该对象。 | FlowGroupElement | ||
在由 relativePosition 参数指定的位置处拆分此 FlowElement 对象,该位置是此元素的文本中的相对位置。 | FlowElement | ||
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。 | Object | ||
返回指定对象的字符串表示形式。 | Object | ||
返回指定对象的原始值。 | Object |
构造函数详细信息
ParagraphElement | () | 构造函数 |
public function ParagraphElement()
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
构造函数 - 表示文本流中的一个段落。
方法详细信息
findNextAtomBoundary | () | 方法 |
public function findNextAtomBoundary(relativePosition:int):int
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
从提供的位置向前扫描,以找到文本中下一个原子的位置并返回索引。术语“atom”既可指图形元素,也可表示字符(包括由字符合并起来的组合),是组成文本行的不可分割的实体。
参数
relativePosition:int — 文本中的起始位置,从 0 开始计算
|
int — 文本中下一个原子的索引
|
相关 API 元素
示例 ( 如何使用本示例 )
此示例从给定偏移处查找段落中的下一个原子边界。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_findNextAtomBoundary extends Sprite { public function ParagraphElement_findNextAtomBoundary() { // create the TextFlow, ParagraphElement and SpanElement objects to hold paragraph var textFlow:TextFlow = new TextFlow(); var paragraph:ParagraphElement = new ParagraphElement(); var span:SpanElement = new SpanElement(); // assign text to the span; add span to paragraph and paragraph to TextFlow span.text = "Hello brave, new world!"; paragraph.addChild(span); textFlow.addChild(paragraph); // assign a controller to the stage and update it to compose and display text textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // find the next atom boundaries from offsets 5 and 10 var atomBoundary:int = paragraph.findNextAtomBoundary(4); trace(atomBoundary); // 5 atomBoundary = paragraph.findNextAtomBoundary(10); trace(atomBoundary); // 11 } } }
findNextWordBoundary | () | 方法 |
public function findNextWordBoundary(relativePosition:int):int
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
返回文本中下一个单词边界的索引。
从提供的位置向前扫描,以找到文本中以一个单词开始或结束的下一个位置。
参数
relativePosition:int — 文本中的起始位置,从 0 开始计算
|
int — 文本中下一个单词边界的索引
|
示例 ( 如何使用本示例 )
此示例从给定偏移处查找段落中的下一个单词边界。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_findNextWordBoundary extends Sprite { public function ParagraphElement_findNextWordBoundary() { // create the TextFlow, ParagraphElement and SpanElement objects to hold paragraph var textFlow:TextFlow = new TextFlow(); var paragraph:ParagraphElement = new ParagraphElement(); var span:SpanElement = new SpanElement(); // assign text to the span; add span to paragraph and paragraph to TextFlow span.text = "Hello brave, new world!"; paragraph.addChild(span); textFlow.addChild(paragraph); // assign a controller to the stage and update it to compose and display text textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // find the next word boundary from offsets 0 and 12 var wordBoundary:int = paragraph.findNextWordBoundary(0); trace(wordBoundary); // 5 wordBoundary = paragraph.findNextWordBoundary(12); trace(wordBoundary); // 13 } } }
findPreviousAtomBoundary | () | 方法 |
public function findPreviousAtomBoundary(relativePosition:int):int
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
从提供的位置向后扫描,以找到文本中上一个原子的位置并返回索引。术语“atom”既可指图形元素,也可表示字符(包括由字符合并起来的组合),是组成文本行的不可分割的实体。
参数
relativePosition:int — 文本中的起始位置,从 0 开始计算
|
int — 文本中上一个簇的索引
|
相关 API 元素
示例 ( 如何使用本示例 )
此示例从给定偏移处查找段落中的上一个原子边界。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_findPreviousAtomBoundary extends Sprite { public function ParagraphElement_findPreviousAtomBoundary() { // create the TextFlow, ParagraphElement and SpanElement objects to hold paragraph var textFlow:TextFlow = new TextFlow(); var paragraph:ParagraphElement = new ParagraphElement(); var span:SpanElement = new SpanElement(); // assign text to the span; add span to paragraph and paragraph to TextFlow span.text = "Hello brave, new world!"; paragraph.addChild(span); textFlow.addChild(paragraph); // assign a controller to the stage and update it to compose and display text textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // find the previous atom boundaries from offsets 6 and 13 var atomBoundary:int = paragraph.findPreviousAtomBoundary(6); trace(atomBoundary); // 5 atomBoundary = paragraph.findPreviousAtomBoundary(13); trace(atomBoundary); // 12 } } }
findPreviousWordBoundary | () | 方法 |
public function findPreviousWordBoundary(relativePosition:int):int
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
返回文本中上一个单词边界的索引。
从提供的位置向后扫描,以找到文本中以一个单词开始或结束的上一个位置。
参数
relativePosition:int — 文本中的起始位置,从 0 开始计算
|
int — 文本中上一个单词边界的索引
|
示例 ( 如何使用本示例 )
此示例从给定偏移处查找段落中的上一个单词边界。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_findPreviousWordBoundary extends Sprite { public function ParagraphElement_findPreviousWordBoundary() { // create the TextFlow, ParagraphElement and SpanElement objects to hold paragraph var textFlow:TextFlow = new TextFlow(); var paragraph:ParagraphElement = new ParagraphElement(); var span:SpanElement = new SpanElement(); // assign text to the span; add span to paragraph and paragraph to TextFlow span.text = "Hello brave, new world!"; paragraph.addChild(span); textFlow.addChild(paragraph); // assign a controller to the stage and update it to compose and display text textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // find the previous word boundary from offsets 0 and 12 var wordBoundary:int = paragraph.findPreviousWordBoundary(22); trace(wordBoundary); // 17 wordBoundary = paragraph.findPreviousWordBoundary(11); trace(wordBoundary); // 6 } } }
getNextParagraph | () | 方法 |
public function getNextParagraph():ParagraphElement
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
返回该段落之后的段落,如果不再有段落则返回 null。
返回ParagraphElement — 下一个段落,如果不再有段落则返回 null。
|
相关 API 元素
示例 ( 如何使用本示例 )
此示例从 xml 标记导入三个文本段落,使用 getChildAtIndex(0) 访问第一个段落,并使用 getNextParagraph() 访问第二个段落。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_getNextParagraph extends Sprite { public function ParagraphElement_getNextParagraph() { // create TextFlow object var textFlow:TextFlow = new TextFlow(); // create content for TextFlow using XML markup var simpleText:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<flow:TextFlow xmlns:flow=\"http://ns.adobe.com/textLayout/2008\">"+ "<flow:p>"+ "<flow:span>This is the first paragraph.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>This is the second paragraph.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>This is the third paragraph.</flow:span>"+ "</flow:p>"+ "</flow:TextFlow>"; // import the xml markup into a TextFlow object and display it on the stage textFlow = TextConverter.importToFlow(simpleText, TextConverter.TEXT_LAYOUT_FORMAT); textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // get first paragraph var p:ParagraphElement = textFlow.getChildAt(0) as ParagraphElement; // get next paragraph and display its content var nextParagraph:ParagraphElement = p.getNextParagraph(); trace("nextParagraph.text is: " + nextParagraph.getText()); } } }
getPreviousParagraph | () | 方法 |
public function getPreviousParagraph():ParagraphElement
语言版本: | ActionScript 3.0 |
运行时版本: | Flash Player 10, AIR 1.5 |
返回该段落之前的段落,如果该段落是 TextFlow 中的第一个段落,则返回 null。
返回ParagraphElement |
相关 API 元素
示例 ( 如何使用本示例 )
此示例从 xml 标记导入三个文本段落,使用 getChildAtIndex(1) 访问第二个段落,并使用 getPreviousParagraph() 访问第一个段落。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; public class ParagraphElement_getPreviousParagraph extends Sprite { public function ParagraphElement_getPreviousParagraph() { // create TextFlow object var textFlow:TextFlow = new TextFlow(); // create content for TextFlow using XML markup var simpleText:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<flow:TextFlow xmlns:flow=\"http://ns.adobe.com/textLayout/2008\">"+ "<flow:p>"+ "<flow:span>This is the first paragraph.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>This is the second paragraph.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>This is the third paragraph.</flow:span>"+ "</flow:p>"+ "</flow:TextFlow>"; // import the xml markup into a TextFlow object and display it on the stage textFlow = TextConverter.importToFlow(simpleText, TextConverter.TEXT_LAYOUT_FORMAT); textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); // get second paragraph (first = 0) var p:ParagraphElement = textFlow.getChildAt(1) as ParagraphElement; // get previous paragraph and display its content var prevParagraph:ParagraphElement = p.getPreviousParagraph(); trace("prevParagraph.text is: " + prevParagraph.getText()); } } }
示例 如何使用本示例
ParagraphElementExample.as
此示例创建三个文本段落并设置其格式。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flash.text.engine.FontPosture; import flashx.textLayout.container.ContainerController; import flashx.textLayout.elements.ParagraphElement; import flashx.textLayout.elements.SpanElement; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.formats.TextLayoutFormat; public class ParagraphElementExample extends Sprite { // create the TextFlow object private var textFlow:TextFlow = new TextFlow(); // Create Strings of text for the paragraphs private var para1String:String = "In the first paragraph of a " private var para1String2:String = "cheap" private var para1String3:String ="Western novel, a cowboy meets a saloon girl."; private var para2String:String = "In the middle of the cheap novel a really bad guy, "+ "who is having a relationship with the saloon girl, sees the cowboy help "+ "her onto her horse as she smiles at him warmly." private var para3String:String = "In the last paragraph of the cheap novel, the cowboy kills "+ "the really bad guy in a shootout in the middle of main street and "+ "then rides into the sunset with the saloon girl on the back of his horse."; public function ParagraphElementExample() { // create a TextLayoutFormat object to use in formatting the paragraphs var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat(); var paragraph1:ParagraphElement = new ParagraphElement(); // create the ParagraphElement objects var paragraph2:ParagraphElement = new ParagraphElement(); var paragraph3:ParagraphElement = new ParagraphElement(); // create the SpanElement objects to hold the content of the paragraphs var p1Span1:SpanElement = new SpanElement(); var p1Span2:SpanElement = new SpanElement(); var p1Span3:SpanElement = new SpanElement(); var p2Span:SpanElement = new SpanElement(); var p3Span:SpanElement = new SpanElement(); // assign the strings of text for the 1st paragraph to spans p1Span1.text = para1String; p1Span2.text = para1String2; p1Span2.fontStyle = FontPosture.ITALIC; // italicize 'cheap' p1Span3.text = para1String3; // add spans to first paragraph paragraph1.addChild(p1Span1); paragraph1.addChild(p1Span2); paragraph1.addChild(p1Span3); // assign the string of text for the 2nd paragraph to a span // and add the span to the second paragraph p2Span.text = para2String; paragraph2.addChild(p2Span); // assign the string of text for the 3rd paragraph to a span // and add the span to the third paragraph p3Span.text = para3String; paragraph3.addChild(p3Span); // add the paragraphs to the TextFlow textFlow.addChild(paragraph1); textFlow.addChild(paragraph2); textFlow.addChild(paragraph3); // set the text formatting properties textLayoutFormat.fontSize = 14; textLayoutFormat.textIndent = 15; textLayoutFormat.paragraphSpaceAfter = 15; textLayoutFormat.paddingTop = 4; textLayoutFormat.paddingLeft = 4; // assign the format object to the TextFlow textFlow.hostFormat = textLayoutFormat; // assign a controller to the stage and update it to compose and // display the text textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); } } }
ParagraphElementExample2.as
此示例将 xml 标记导入到 TextFlow 对象中。xml 标记定义与前一个示例相同的三个文本段落及其格式。
package flashx.textLayout.elements.examples { import flash.display.Sprite; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.container.ContainerController; public class ParagraphElementExample2 extends Sprite { // create the TextFlow object private var textFlow:TextFlow = new TextFlow(); // xml markup that defines the attributes and contents of a text flow private var simpleText:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<flow:TextFlow xmlns:flow=\"http://ns.adobe.com/textLayout/2008\" verticalScrollPolicy=\"auto\" horizontalScrollPolicy=\"auto\" editingMode=\"readWrite\" fontSize=\"14\" textIndent=\"15\" marginBottom=\"15\" paddingTop=\"4\" paddingLeft=\"4\">"+ "<flow:p>"+ "<flow:span>In the first paragraph of a </flow:span>"+ "<flow:span fontStyle=\"italic\">cheap</flow:span>"+ "<flow:span> Western novel, a cowboy meets a saloon girl.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>In the middle of the cheap novel a really bad guy, </flow:span>"+ "<flow:span>who is having a relationship with the saloon girl, sees the cowboy help </flow:span>"+ "<flow:span>her onto her horse as she smiles at him warmly.</flow:span>"+ "</flow:p>"+ "<flow:p>"+ "<flow:span>In the last paragraph of the cheap novel, the cowboy kills the really </flow:span>"+ "<flow:span> bad guy in a shootout in the middle of main street and then rides into the sunset with </flow:span>"+ "<flow:span>the saloon girl on the back of his horse.</flow:span>" + "</flow:p>"+ "</flow:TextFlow>"; public function ParagraphElementExample2() { // import the xml markup into a TextFlow object and display it on the stage textFlow = TextConverter.importToFlow(simpleText, TextConverter.TEXT_LAYOUT_FORMAT); textFlow.flowComposer.addController(new ContainerController(this, 200, 400)); textFlow.flowComposer.updateAllControllers(); } } }
Tue Jun 12 2018, 11:04 AM Z