我提出了一个新问题,因为它是有意义的,因为问题不再相同了。
我在做一个填色游戏。CanvPark_mc是包含创建画布细节和所有笔刷细节的影片剪辑。Huge, Medium和SmallSelected1变量是当你点击画笔时改变的变量,所以你可以识别它们。
我想根据上次点击的笔刷切换光标。这可以通过第一个if参数来实现。现在,这是我要切换的代码,感谢上一个问题中的@NBooo的帮助
var cursor_mc: MovieClip = new MovieClip();
if (CanvPark_mc.HugeSelected1 == true) {
cursor_mc = cursor1_mc; //Big Cursor
removeChild(cursor_mc);
}
if (CanvPark_mc.MediumSelected1 == true) {
cursor_mc = cursor2_mc; //Medium Cursor
removeChild(cursor_mc);
}
if (CanvPark_mc.SmallSelected1 == true) {
cursor_mc = cursor3_mc; //Small Cursor
removeChild(cursor_mc);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
function moveCursor(myEvent: MouseEvent) {
if (CanvPark_mc.SmallSelected1 == false && CanvPark_mc.MediumSelected1 == false && CanvPark_mc.HugeSelected1 == false) {
Mouse.cursor = "auto";
} else if (cursor_mc){
addChild(cursor_mc);
setChildIndex(cursor_mc, this.numChildren - 1);
cursor_mc.x = stage.mouseX;
cursor_mc.y = stage.mouseY;
cursor_mc.mouseChildren = cursor_mc.mouseEnabled = false;
Mouse.hide();
}
}
不幸的是,这段代码的问题在于,每当我单击上述按钮时,光标就会消失。它不会将自己更改为我之前制作的任何MovieClips。
请注意if块中的removeChild是希望在过去单击cursor_mc后删除屏幕上先前的实例。
在测试中,只有在第一个if块中,其中一个参数是=而不是==。
的例子:
if (CanvPark_mc.HugeSelected1 == true) {
cursor_mc = cursor1_mc; // Big Cursor
removeChild(cursor_mc);
}
if (CanvPark_mc.MediumSelected1 == true) {
cursor_mc = cursor2_mc; //Medium Cursor
removeChild(cursor_mc);
}
if (CanvPark_mc.SmallSelected1 = true) {
cursor_mc = cursor3_mc; //This is the one he'll run, showing the smallest cursor
removeChild(cursor_mc);
}
此外,如果它们都简化为=,代码将选择列表中最后一个if。我认为我的代码有问题,经过几个小时的尝试,我不知道它是什么。
你们谁能帮我弄明白这个吗?我找到了自己问题的答案,所以我将把代码贴出来帮助别人。
var cursor_mc: MovieClip = new MovieClip();
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
function moveCursor(myEvent: MouseEvent) {
if (CanvPark_mc.HugeSelected1 == true) {
cursor_mc = cursor1_mc;
cursor1_mc.visible = true;
cursor2_mc.visible = false;
cursor3_mc.visible = false;
}
if (CanvPark_mc.MediumSelected1 == true) {
cursor_mc = cursor2_mc;
cursor1_mc.visible = false;
cursor2_mc.visible = true;
cursor3_mc.visible = false;
}
if (CanvPark_mc.SmallSelected1 == true) {
cursor_mc = cursor3_mc;
cursor1_mc.visible = false;
cursor2_mc.visible = false;
cursor3_mc.visible = true;
}
if (CanvPark_mc.SmallSelected1 == false && CanvPark_mc.MediumSelected1 == false && CanvPark_mc.HugeSelected1 == false) {
Mouse.cursor = "auto";
} else if (cursor_mc) {
addChild(cursor_mc);
setChildIndex(cursor_mc, this.numChildren - 1);
cursor_mc.x = stage.mouseX;
cursor_mc.y = stage.mouseY;
cursor_mc.mouseChildren = cursor_mc.mouseEnabled = false;
Mouse.hide();
}
}
if块不在函数内部,因此它没有将代码关联在一起。我把它放在里面测试,它起作用了。因为当您单击鼠标以将鼠标更改为画笔时,Movieclip开始跟随您的鼠标。如果你换成另一个画笔,影片剪辑就会留在那里。这是通过在if中切换它的可见性来修复的。:)
运行正常
希望这能帮助到一些人!