flash on 2014-11-17
♥0 |
Line 51 |
Modified 2014-11-17 17:17:10 |
MIT License
archived:2017-03-20 03:17:45
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nUTp
*/
package {
import flash.display.Sprite;
import flash.text.*;
import flash.events.*;
public class FlashTest extends Sprite {
private var tf:TextField;
private var tf2:TextField;
public function FlashTest() {
// write as3 code here..
tf = new TextField();
addChild(tf);
tf.border = true;
tf.type="input";
tf.multiline=true;
tf.text = "test";
tf.y = 200;
tf.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
tf2 = new TextField();
addChild(tf2);
tf2.x = 200;
tf2.text="test";
}
private function onMove(e:MouseEvent):void{
var mx:Number=e.target.mouseX;
var my:Number=e.target.mouseY;
tf2.text = "x: "+mx.toString()+"\ny: "+my.toString();
var n:int = tf.getLineIndexAtPoint(mx,my);//指定ポイントの行
tf2.appendText("\n"+n.toString());
tf2.appendText("\n"+tf.getLineText(n));
var st:int = tf.getLineOffset(n);
var end:int = tf.getLineLength(n);
tf2.appendText("\n"+st+" "+end);
font(tf,n);
}
private function font(t1:TextField,n:int):void{
//検索ヒット
var newFormat2:TextFormat = new TextFormat();
newFormat2.size = 15;
newFormat2.font = "Arial";
newFormat2.color = 0xcc0000;
newFormat2.italic = true;
//通常フォーマット
var Format2:TextFormat = new TextFormat();
Format2.size = 12;
Format2.font = "Arial";
Format2.color = 0x000000;
Format2.italic = false;
t1.setTextFormat(Format2,0,t1.length);//デフォルトフォーマット
var st:int = t1.getLineOffset(n);
var end:int = st+t1.getLineLength(n);
t1.setTextFormat(newFormat2,st,end);//デフォルトフォーマット
}
}
}