我正在尝试让我的游戏在按下按钮时更改光标。然而,在按下其中一个按钮后,我无法再次更改它(好像光标挡住了)。我想设置mouseCursor.mouseEnabled = false;
会解决它,但似乎没有。
这是我的代码,有人可以告诉我,我做错了吗?
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
import flash.utils.*;
import flash.ui.*;
import Game.*;
public class GameController extends MovieClip
{
private var mouseCursor:MovieClip;
public function GameController()
{
}
private function followMouse(evt:Event)
{
mouseCursor.x = mouseX;
mouseCursor.y = mouseY;
}
public function startGame()
{
needleOn = false;
mcGameUI.btnMixBlue.addEventListener(
MouseEvent.CLICK, mixBlue);
mcGameUI.btnMixRed.addEventListener(
MouseEvent.CLICK, mixRed);
mcGameUI.btnMixYellow.addEventListener(
MouseEvent.CLICK, mixYellow);
mcGameUI.btnNeedle.addEventListener(
MouseEvent.CLICK, activateNeedle);
mcGameUI.mouseEnabled = false;
}
private function mixBlue(evt:MouseEvent)
{
if (mouseCursor != null)
{
removeChild(mouseCursor);
mouseCursor.removeEventListener(Event.ENTER_FRAME,followMouse);
mouseCursor = null;
}
mouseCursor = new BlueBubble(mouseX,mouseY);
mouseCursor.gotoAndPlay("idle");
mouseCursor.mouseEnabled = false;
mouseCursor.addEventListener(Event.ENTER_FRAME,followMouse);
addChild(mouseCursor);
}
private function mixRed(evt:MouseEvent)
{
if (mouseCursor != null)
{
removeChild(mouseCursor);
mouseCursor.removeEventListener(Event.ENTER_FRAME,followMouse);
mouseCursor = null;
}
mouseCursor = new RedBubble(mouseX,mouseY);
mouseCursor.gotoAndPlay("idle");
mouseCursor.mouseEnabled = false;
mouseCursor.addEventListener(Event.ENTER_FRAME,followMouse);
addChild(mouseCursor);
}
private function mixYellow(evt:MouseEvent)
{
if (mouseCursor != null)
{
removeChild(mouseCursor);
mouseCursor.removeEventListener(Event.ENTER_FRAME,followMouse);
mouseCursor = null;
}
mouseCursor = new YellowBubble(mouseX,mouseY);
mouseCursor.gotoAndPlay("idle");
mouseCursor.mouseEnabled = false;
mouseCursor.addEventListener(Event.ENTER_FRAME,followMouse);
addChild(mouseCursor);
}
private function activateNeedle(evt:MouseEvent)
{
if (mouseCursor != null)
{
removeChild(mouseCursor);
mouseCursor = null;
mouseCursor.removeEventListener(Event.ENTER_FRAME,followMouse);
}
mouseCursor = new Needle();
mouseCursor.mouseEnabled = false;
addChild(mouseCursor);
mouseCursor.addEventListener(Event.ENTER_FRAME,followMouse);
}
}
}
答案 0 :(得分:1)
你应该设置:
mouseCursor.mouseEnabled = false;
mouseCursor.mouseChildren = false;
mouseEnabled仅关闭容器mouseCursor
,但在此剪辑中,您仍然可以使用mouseEnabled元素,因此也应关闭mouseChildren
。
mouseChildren在DisplayObjectContainer中定义,这意味着由形状或位图构成的游标将不具有此属性,因此您需要先测试它是否存在。
if(mouseCursor is DisplayObjectContainer){
{
mouseCursor.mouseChildren = false;
}