作者wind50321 (小顺)
看板Flash
标题for回圈里的滑鼠侦听事件跟取消
时间Sat Jan 9 19:22:39 2010
大家好,我是 AS的新手
在书中我学到一个范例
然後我觉得他的 AS不太完善想做修改
这个档案是要挑出动作不一样的 MC
我在for回圈里面
替三个 MC设定了 RollOver、RollOut、Click三个侦听事件
然後想在 Click这个侦听事件的函数中
用 removeEventListener()取消上述这三个侦听事件
包含 Click本身
但是好像没有效果
黄色的部分是我加的地方
但是侦听事件还是照样执行...
不知道是哪里出了问题
还是我的思考逻辑错误呢?
希望大家帮帮我
档案 differ.fla
http://goo.gl/tcIc
-----------------------------程式码---------------------------
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++) {
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);
function onMouseRollOver(e:MouseEvent) {
e.target.glow_mc.visible=true;
}
function onMouseRollOut(e:MouseEvent) {
e.target.glow_mc.visible=false;
}
function onMouseClick(e:MouseEvent) {
again_mc.visible=true;
again_mc.buttonMode=true;
for (var i:int=1; i<=monkeyNO; i++) {
root["monkey"+i+"_mc"].
removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOut);
root["monkey"+i+"_mc"].
removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
root["monkey"+i+"_mc"].
removeEventListener(MouseEvent.CLICK,onMouseClick);
root["monkey"+i+"_mc"].buttonMode=false;
}
var tempName:String=e.currentTarget.name.substr(6,1);
if (tempName==String(rightNO)) {
right_mc.visible=true;
wrong_mc.visible=false;
} else {
wrong_mc.visible=true;
right_mc.visible=false;
}
}
if (i==rightNO) {
root["monkey"+i+"_mc"].gotoAndStop(typeNO);
} else {
root["monkey"+i+"_mc"].gotoAndStop(type1NO);
}
root["monkey"+i+"_mc"].buttonMode=true;
}
again_mc.addEventListener(MouseEvent.CLICK,doinit);
function doinit(e:MouseEvent):void {
init();
}
}
-------------------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.169.179.59
※ 编辑: wind50321 来自: 118.169.179.59 (01/09 21:39)
1F:→ wind50321:monkey1_mc、monkey2_mc、monkey3_mc为三个猴子动画 01/09 21:40
2F:→ wind50321:猴子实体物件底下有1.2.3影格为三个动作 01/09 21:42
3F:→ wind50321:glow_mc为猴子动画底下的光晕图层 01/09 21:43
4F:→ wind50321:主要是用乱数决定猴子的动作 其中一只的动作不一样 01/09 21:49
5F:→ emily114005:程式码里面没有removeEventListener 你要的效果是? 01/09 22:25
6F:→ wind50321:我想在Click的函数里面加 效果一开始有说了 01/09 23:06
7F:→ wind50321:让Click了以後,RollOver、RollOut、Click都不能再作用 01/09 23:07
8F:→ gameking:直接在onMouseClick函式里加三个REMOVE就好啦~试试看? 01/10 02:54
※ 编辑: wind50321 来自: 118.169.179.59 (01/10 10:41)
※ 编辑: wind50321 来自: 118.169.179.59 (01/10 10:43)
※ 编辑: wind50321 来自: 118.169.179.59 (01/10 10:45)
※ 编辑: wind50321 来自: 118.169.179.59 (01/10 10:46)
※ 编辑: wind50321 来自: 118.169.179.59 (01/10 11:09)