以A的3次方为例,我们输入以下代码:/**
* 部分代码参考Adobe文档:
* http://help.adobe.com/zh_CN/AS3LCR/Flash_10.0/flash/text/engine/package-detail.html
* by kingnare.com
*/package
{
import __AS3__.vec.Vector; import flash.display.Sprite;
import flash.text.engine.ContentElement;
import flash.text.engine.ElementFormat;
import flash.text.engine.FontDescription;
import flash.text.engine.FontWeight;
import flash.text.engine.GroupElement;
import flash.text.engine.TextBaseline;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine; [SWF(width="800", height="600", backgroundColor="#FFFFFF", framerate="24")] public class TextEngineTest_TextBaseline extends Sprite
{
public function TextEngineTest_TextBaseline()
{
//字体属性
var fd1:FontDescription = new FontDescription("Arial");
//格式设置
var ef1:ElementFormat = new ElementFormat(fd1, 16); var fd2:FontDescription = new FontDescription("Arial");
var ef2:ElementFormat = new ElementFormat(fd2, 10);
//将基线上移8个像素
ef2.baselineShift = -8; //创建已设置格式的文本的字符串
var te1:TextElement = new TextElement("A",ef1);
var te2:TextElement = new TextElement("3",ef2); var groupVector:Vector.<ContentElement> = new Vector.<ContentElement>();
groupVector.push(te1, te2);
//组成ContentElement集合
var groupElement = new GroupElement(groupVector);
//创建文本块
var textBlock:TextBlock = new TextBlock();
textBlock.content = groupElement;
//显示文本
createTextLines(textBlock);
} //显示文本
private function createTextLines(textBlock:TextBlock):void
{
var yPos = 20;
var line_length:Number = 450;
var textLine:TextLine = textBlock.createTextLine(null,line_length);
while (textLine)
{
addChild(textLine);
textLine.x = 15;
yPos += textLine.height + 8;
textLine.y=yPos;
textLine=textBlock.createTextLine(textLine,line_length);
}
}
}
}