[問題] 滑鼠偵聽事件改了程式碼還是無法取消(ꨠ…
大家好,我是 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)
→
01/09 21:40, , 1F
01/09 21:40, 1F
→
01/09 21:42, , 2F
01/09 21:42, 2F
→
01/09 21:43, , 3F
01/09 21:43, 3F
→
01/09 21:49, , 4F
01/09 21:49, 4F
→
01/09 22:25, , 5F
01/09 22:25, 5F
→
01/09 23:06, , 6F
01/09 23:06, 6F
→
01/09 23:07, , 7F
01/09 23:07, 7F
→
01/10 02:54, , 8F
01/10 02:54, 8F
※ 編輯: 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)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):