得分不能正确添加ActionScript3

时间:2017-05-04 23:23:39

标签: actionscript-3 flash actionscript adobe

我为我的项目设置了这个分数计数器,但不是添加+1或减去-1,而是减去2并添加7.这是我正在使用的代码。

我有它所以一个页面有两个按钮(startBTN和endBTN),当你点击startBTN时,它会在这个swf上加载另一个swf并添加一个点。但是,当它这样做时,它增加了7分。另一个按钮用于减去一个点并拉出相应的swf,而是减去2。

我在一个单独的页面上尝试了这个,即使它们没有链接在一起,它也会减去4而不是2。

var saveDataObject:SharedObject;
var currentScore:int;

init(); // this line goes directly beneath the variables

function init():void{ // call once to set everything up

saveDataObject = SharedObject.getLocal("test"); // give the save data a location
 currentScore = 0; //start with 0 score

startBTN.addEventListener(MouseEvent.CLICK, addScore); // clicking on +1
 endBTN.addEventListener(MouseEvent.CLICK, subtractScore); // clicking on Save

function addScore(e:MouseEvent):void{
 currentScore += 1; // add 1 to the score
 updateScoreText(); // update the textfield
}
function subtractScore(e:MouseEvent):void{
 currentScore -= 1; // add 1 to the score
 updateScoreText(); // update the textfield
}

function saveData(e:MouseEvent):void{
 saveDataObject.data.savedScore = currentScore; // set the saved score to the current score
 trace("Data Saved!");
 saveDataObject.flush(); // immediately save to the local drive
 trace(saveDataObject.size); // this will show the size of the save file, in bytes
}

function loadData():void{
 currentScore = saveDataObject.data.savedScore; // set the current 
score to the saved score
 trace("Data Loaded!");
 //return currentScore;
}

function updateScoreText():void
{
 txtScore.text = "Score: " + String(currentScore); // set the text property of the txtScore
 trace(currentScore);
}


 if(saveDataObject.data.savedScore == null){ // checks if there is save data
      trace("No saved data yet."); // if there isn't any data on the computer...
      saveDataObject.data.savedScore = currentScore; // ...set the savedScore to 0
 } else {
      trace("Save data found."); // if we did find data...
      loadData(); // ...load the data
 }

 //updateScoreText(); // finally, update the text field
}

0 个答案:

没有答案