我有點新的閃存as3,但我做課件的應用程序,涉及到拖動文字到合適的目標與分數,如果正確匹配,還包括一個20秒計時器,應該做一個練習。但是我的問題是,在我將正確的單詞拖到自己的位置並獲得相關分數後(我使用了10分每個正確答案),我仍然可以拖動單詞並使用每個拖動的單詞重複評分(即,我想不能拖動單詞拖動),這使用戶得分超過更高的分數(即90分,因爲有9個詞要拖動)。拖放與目標
這是我的編碼;
stop();
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
var myscore1 = 0; score.text = myscore1+"";
var hitArray:Array = new Array(love_tgt, am_stud_tgt, living_tgt, is_improv_tgt, speak_tgt,
means_tgt, are_help_tgt, want_tgt, miss_tgt);
var dropArray:Array = new Array(love, am_stud, living, is_improv, speak, means, are_help,
want, miss);
var positionsArray:Array = new Array();
for (var i:int = 0; i < dropArray.length; i++) {
dropArray[i].buttonMode = true;
dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}
function mdown(e:MouseEvent):void {
e.currentTarget.startDrag();
setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}
function mUp(e:MouseEvent):void {
var dropIndex:int = dropArray.indexOf(e.currentTarget);
var target:MovieClip = e.currentTarget as MovieClip;
target.stopDrag();
if (target.hitTestObject(hitArray[dropIndex])) {
myscore1+=10;
score.text = myscore1+"";
target.x = hitArray[dropIndex].x;
target.y = hitArray[dropIndex].y;
}else{
target.x = positionsArray[dropIndex].xPos;
target.y = positionsArray[dropIndex].yPos;
}
}
var myTimer1:Timer = new Timer(1000);
myTimer1.addEventListener(TimerEvent.TIMER, countdownHandler1);
function countdownHandler1(event:TimerEvent):void{
countdown.text = 20-myTimer1.currentCount+" s remaining";
if(myTimer1.currentCount==20){
gotoAndStop(46);
} }
myTimer1.start();
}
請正確格式化您的代碼。我只是嘗試編輯這個爛攤子,但我害怕破壞一些東西。 – lxg 2014-09-13 09:20:54