单击button1时,光标变为'movieclip' 我希望这个movieclip光标切换回常规光标 再次单击button1时,请打开和关闭该功能。
我的问题是,是否有可能在这里使用某种布尔值来打开和关闭函数或者我是否在错误的方向? 提前谢谢!
button1.addEventListener(MouseEvent.CLICK,wipe);
function wipe(e:Event):void
{
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent)
{
cursor.x = mouseX;
cursor.y = mouseY;
}
}
答案 0 :(得分:0)
尝试
protected function wipe(e:Event):void {
if (stage.hasEventListener(MouseEvent.MOUSE_MOVE, follow) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
} else {
stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
}
}
我将移动擦除的定义。这甚至有用吗?
如果您需要在舞台上直接拥有其他MOUSE_MOVE听众,那么您可能想要更像以下内容:
protected var isFollowing:Boolean;
protected function wipe(e:Event):void {
if (isFollowing) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
} else {
stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
}
isFollowing = !isFollowing;
}
注意:我假设您要将您的代码放入文档类中,因为我总是认为如果您足够关心像Stack Overflow这样的地方,那么您希望使用良好的实践。< / p>
答案 1 :(得分:0)
var isMC:Boolean=false;
button1.addEventListener(MouseEvent.CLICK,wipe);
cursor.visible=false;
function wipe(e:Event):void
{
if(isMC==false){
cursor.visible=true;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent)
{
cursor.x = mouseX;
cursor.y = mouseY;
}
isMC=true;}else{Mouse.show();
cursor.visible=false;
isMC=false
}}
希望这有帮助。