【AS3代码】更换鼠标箭头样式,并跟随鼠标!
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class Main extends Sprite
{
private var flag:Boolean = new Boolean();
public function Main():void
{
//创建一个新光标(小方块)
var a:Sprite = new Sprite();
a.graphics.beginFill(0xff0000);
a.graphics.drawRect(0,0,50,50);
a.graphics.endFill();
this.addChild(a);
a.startDrag(true); //新光标跟随鼠标
Mouse.hide(); //隐藏原有光标
stage.addEventListener(MouseEvent.CLICK, an); //监听舞台是否被点击
flag = false; //标识原鼠标箭头为隐藏状态
}
//鼠标点击舞台后激发的事件
private function an(evt:MouseEvent):void
{
if(flag == false)
{
Mouse.show(); //显示原有光标
}
else
{
Mouse.hide(); //隐藏原有光标
}
flag = !flag; //隐藏和显示状态转换
}
}
}
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class Main extends Sprite
{
private var flag:Boolean = new Boolean();
public function Main():void
{
//创建一个新光标(小方块)
var a:Sprite = new Sprite();
a.graphics.beginFill(0xff0000);
a.graphics.drawRect(0,0,50,50);
a.graphics.endFill();
this.addChild(a);
a.startDrag(true); //新光标跟随鼠标
Mouse.hide(); //隐藏原有光标
stage.addEventListener(MouseEvent.CLICK, an); //监听舞台是否被点击
flag = false; //标识原鼠标箭头为隐藏状态
}
//鼠标点击舞台后激发的事件
private function an(evt:MouseEvent):void
{
if(flag == false)
{
Mouse.show(); //显示原有光标
}
else
{
Mouse.hide(); //隐藏原有光标
}
flag = !flag; //隐藏和显示状态转换
}
}
}