作者sPin (我转)
看板Flash
标题Re: [问题] 滑鼠侦听事件改了程式码还是无法取消(ꨠ…
时间Mon Jan 11 01:19:05 2010
看了一下档案
我猜想是因为你把所有东西都包在init()里了
所以当你在CLICK事件的函数中移除其他监听事件
才会发生这种状况
然後试着把里面的东西大概拆出来
可以达成你要的效果
我也是新手不知道说的对不对 参考看看罗
程式码如下
--
var monkeyNO:int=3;
var rightNO:int;
var typeNO:int;
var type1NO:int;
init();
function init():void {
again_mc.visible=false;
right_mc.visible=false;
wrong_mc.visible=false;
right_mc.x=375;
right_mc.y=158;
wrong_mc.x=375;
wrong_mc.y=158;
do {
rightNO=Math.floor(Math.random()*3+1);
} while (rightNO>3);
do {
typeNO=Math.floor(Math.random()*3+1);
} while (typeNO>3);
do {
type1NO=Math.floor(Math.random()*3+1);
} while (type1NO>3);
while (type1NO==typeNO) {
type1NO=Math.floor(Math.random()*3+1);
}
for (var i:int=1; i<=monkeyNO; i++) {
if (i==rightNO) {
root["monkey"+i+"_mc"].gotoAndStop(typeNO);
} else {
root["monkey"+i+"_mc"].gotoAndStop(type1NO);
}
root["monkey"+i+"_mc"].glow_mc.visible=false;
root["monkey"+i+"_mc"].addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
root["monkey"+i+"_mc"].addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
root["monkey"+i+"_mc"].addEventListener(MouseEvent.CLICK,onMouseClick);
root["monkey"+i+"_mc"].buttonMode=true;
}
}
function onMouseRollOver(e:MouseEvent) {
e.target.glow_mc.visible=true;
}
function onMouseRollOut(e:MouseEvent) {
e.target.glow_mc.visible=false;
}
function onMouseClick(e:MouseEvent) {
var tempName:String=e.currentTarget.name.substr(6,1);
for (var j:uint=1; j<=3; j++) {
root["monkey"+j+"_mc"].glow_mc.visible=false;
root["monkey"+j+"_mc"].removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
root["monkey"+j+"_mc"].removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
root["monkey"+j+"_mc"].removeEventListener(MouseEvent.CLICK,onMouseClick);
root["monkey"+j+"_mc"].buttonMode=false;
}
if (tempName==String(rightNO)) {
right_mc.visible=true;
wrong_mc.visible=false
again_mc.visible=true;
again_mc.buttonMode=true;
} else {
wrong_mc.visible=true;
right_mc.visible=false;
again_mc.visible=true;
again_mc.buttonMode=true;
}
}
again_mc.addEventListener(MouseEvent.CLICK,doinit);
function doinit(e:MouseEvent):void {
init();
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.37.94.149
1F:推 wind50321:嗯嗯…做出来了!不过逻辑还是不太懂 要再想一下 01/11 07:37