Re: [問題] 滑鼠偵聽事件改了程式碼還是無法取消(ꨠ…

看板Flash作者 (我轉)時間16年前 (2010/01/11 01:19), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
看了一下檔案 我猜想是因為你把所有東西都包在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

01/11 07:37, , 1F
嗯嗯…做出來了!不過邏輯還是不太懂 要再想一下
01/11 07:37, 1F
文章代碼(AID): #1BIWmCTT (Flash)
文章代碼(AID): #1BIWmCTT (Flash)