import flash.events.MouseEvent; barPic1_mc.gotoAndStop(1); //拉霸圖1先停在影格1 barPic2_mc.gotoAndStop(2); //拉霸圖2先停在影格2 barPic3_mc.gotoAndStop(3); //拉霸圖1先停在影格3 //設定停止按鈕無法動作 stop_btn.enabled = false; // 新增numArray陣列,用來記錄拉霸開獎數字 var numArray:Array=new Array(); numArray[0]=1; numArray[1]=2; numArray[2]=3; //按下開始按鈕,執行自訂函數slot_start start_btn.addEventListener(MouseEvent.CLICK,slot_start); function slot_start(me:MouseEvent) { barPic1_mc.play(); //拉霸圖案1播放 barPic2_mc.play(); //拉霸圖案2播放 barPic3_mc.play(); //拉霸圖案3播放 winning_mc.gotoAndStop(1); //中獎動畫停在影格1 stop_btn.enabled = true; //停止按鈕可以動作 } //按下停止按鈕,執行自訂函數slot_stop stop_btn.addEventListener(MouseEvent.CLICK, slot_stop); function slot_stop(me:MouseEvent) { //先判斷如果停止按鈕是正常的,則進行迴圈3次,取得3個亂數,並存入陣列 if (stop_btn.enabled == true) { //迴圈跑三次,取得三次亂數存入陣列 for(var i:int=1; i<=3; i++) { //由1-6中,隨機取得一個數字 var num = Math.floor(Math.random() *6 + 1); //將取得亂數值存入陣列中 numArray[i-1] = num; //呼叫stop_bar函數,並傳遞值 stop_bar(i, num); } } // 設定停止按鈕狀態為false無法動作 stop_btn.enabled = false; //判斷如果陣列中的三個數字相同,則播放中獎動畫 if (numArray[0] == numArray [1] && numArray[0] == numArray[2]) { winning_mc.gotoAndStop(2); //將中獎動畫停在影格2 } } //將拉霸圖案影片片段停在各自影格 function stop_bar(mc, stopnum) { switch (mc) { case 1: barPic1_mc.gotoAndStop(stopnum); case 2: barPic2_mc.gotoAndStop(stopnum); case 3: barPic3_mc.gotoAndStop(stopnum); } }