看板 Flash 關於我們 聯絡資訊
大家好,我是 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)
wind50321:monkey1_mc、monkey2_mc、monkey3_mc為三個猴子動畫 01/09 21:40
wind50321:猴子實體物件底下有1.2.3影格為三個動作 01/09 21:42
wind50321:glow_mc為猴子動畫底下的光暈圖層 01/09 21:43
wind50321:主要是用亂數決定猴子的動作 其中一隻的動作不一樣 01/09 21:49
emily114005:程式碼裡面沒有removeEventListener 你要的效果是? 01/09 22:25
wind50321:我想在Click的函數裡面加 效果一開始有說了 01/09 23:06
wind50321:讓Click了以後,RollOver、RollOut、Click都不能再作用 01/09 23:07
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)