Flash 问题,请问 TextField 动态文本框 如何获取当前光标所在的行数?
2个回答
展开全部
//TextField类的方法:getLineIndexAtPoint(x:Number, y:Number):int
//在 x 和 y 参数指定的位置返回从零开始的行索引值。
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
public class TextField_getLineIndexAtPointExample extends Sprite {
private var poem:TextField = new TextField();
private var poemCopy:TextField = new TextField();
public function TextField_getLineIndexAtPointExample() {
poem.border = true;
poem.autoSize = TextFieldAutoSize.LEFT;
poem.x = 10;
poem.wordWrap = false;
poemCopy.height = 250;
poemCopy.width = 270;
poemCopy.y = 230;
poemCopy.x = 10;
poemCopy.background = true;
poemCopy.border = true;
poemCopy.wordWrap = false;
poem.appendText("Let me not to the marriage of true minds\n"
+ "Admit impediments. love is not love\n"
+ "Which alters when it alteration finds\n"
+ "Or bends with the remover to remove:\n"
+ "O no! it is an ever-fixed mark\n"
+ "That looks on tempests and is never shaken;\n"
+ "It is the star to every wandering bark,\n"
+ "Whose worth's unknown, although his height be taken.\n"
+ "Love's not Time's fool, though rosy lips and cheeks\n"
+ "Within his bending sickle's compass come:\n"
+ "Love alters not with his brief hours and weeks,\n"
+ "But bears it out even to the edge of doom.\n"
+ "If this be error and upon me proved,\n"
+ "I never writ, nor no man ever loved.");
poem.addEventListener(MouseEvent.CLICK, clickHandler);
this.addChild(poem);
this.addChild(poemCopy);
}
private function clickHandler(e:MouseEvent):void {
var index:int = poem.getLineIndexAtPoint(e.localX, e.localY);
var s:String;
s = poem.getLineText(index);
poemCopy.appendText(s + "\n");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询