我试图让标准鼠标光标在y>时消失。 85
var myCursor: Sprite;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
function init() {
if (y>85) {
Mouse.hide(); // This would hide the standard cursor
}
myCursor = new MyCursorClass();
myCursor.mouseEnabled = false;
myCursor.visible = false;
addChild(myCursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
}
function mouseMoveHandler(evt: MouseEvent): void {
myCursor.visible = true;
myCursor.x = evt.stageX;
myCursor.y = evt.stageY;
}
function mouseLeaveHandler(evt:MouseEvent): void {
myCursor.visible = false;
}
init();
但它不起作用..我不知道原因。有帮助吗?我有一个if语句声明标准鼠标在某个级别时被隐藏。
答案 0 :(得分:0)
我注意到你在触发MOUSE_LEAVE事件时试图隐藏光标,但你需要为每个MOUSE_MOVE调用init函数,以便检查Mouse.y是否为y
的次要。< / p>
这可能对您有用:
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
var myCursor:Sprite;
myCursor = new MyCursorClass();
myCursor.mouseEnabled = false;
myCursor.visible = false;
addChild(myCursor);
function showCustomCursor(action:Boolean) {
if (action) {
Mouse.hide();
myCursor.visible = true;
} else {
Mouse.show();
myCursor.visible = false;
}
}
function mouseMoveHandler(evt:MouseEvent):void {
myCursor.x = evt.stageX;
myCursor.y = evt.stageY;
// check for every mouse move event
showCustomCursor(evt.stageY > 85); // if evt.stageY > 85
evt.updateAfterEvent(); // Smoothing
}
function mouseLeaveHandler(evt:MouseEvent): void {
showCustomCursor(false); // Show the default cursor
}
// Init
showCustomCursor(myCursor.y > 85);