Actionscript 3 未正确添加ActionScript3的分数
我的项目有这个计分器,但它不是加+1或减-1,而是减2加7。这是我正在使用的代码 我有这样一个页面有两个按钮(startBTN和endBTN),当你点击startBTN时,它会在这个swf上加载另一个swf并添加一个点。然而,当它这样做时,它会增加7分。另一个按钮用于减去一个点,然后拉起相应的swf,然后减去2 我在另一个页面上尝试了这个方法,它将减去4而不是2,即使它们没有链接在一起Actionscript 3 未正确添加ActionScript3的分数,actionscript-3,flash,actionscript,adobe,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;
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
}
不知道现在是否已解决,但不要将函数放在其他函数中…此代码应该工作,您尝试加载的swf是什么?不知道现在是否已解决,但不要将函数放在其他函数中…此代码应该工作,您尝试加载的swf是什么?