读书人

[as3]TextField,鼠标透过文本变色

发布时间: 2012-12-25 16:18:28 作者: rapoo

[as3]TextField,鼠标经过文本变色

package{import flash.display.Sprite;import flash.events.Event;import flash.text.TextField;import flash.text.TextFormat;public class MyMP3Demo extends Sprite{private var myText:TextField;public function MyMP3Demo(){//---------code by ycccc8202----------myText = new TextField()myText.text="在人生的高速路上已经连续转错了不少弯";myText.width=myText.height=300;myText.x=myText.y=100;var myTextFormat_old:TextFormat = new TextFormat();myTextFormat_old.color="0x000000";myTextFormat_old.size=12;var myTextFormat_new:TextFormat = new TextFormat();myTextFormat_new.color="0xff0000";myTextFormat_new.size=12;function enterFrameListener(event:Event) {myText.setTextFormat(myTextFormat_old);var charIndex:int = myText.getCharIndexAtPoint(myText.mouseX,myText.mouseY);//不断取得指定位置的字符索引if(charIndex==-1){//如果鼠标移出文本return;}myText.setTextFormat(myTextFormat_new,charIndex,charIndex+1);}addEventListener(Event.ENTER_FRAME, enterFrameListener);//注册桢循环事件addChild(myText)}}}
1 楼 rockyf 2012-05-08 这都行。。。我觉得直接用<a/> + css更方便点吧。

读书人网 >编程

热点推荐