嘿大家所以我一直在试图TI完成,但没有成功是如何显示我的影片剪辑对象名为 achiev_10
在 NSCore公司
这是一个数等于10。
Hey everyone so what I've been trying ti accomplish with no success is how to display my Movie Clip object named achiev_10
when the nScore
which is a number equal to 10.
下面是我至今在我的共享对象数据。
Here is what I have so far in my Shared Object Data.
在我的构造我有这样的:
In my Constructor I have this:
//Initialize our shared object give it a path to save local data
sharedObject = SharedObject.getLocal("GeometryBlast");
if (sharedObject.data.highScore == null)
{
// checks if there is save data
trace("No saved data yet."); // if there isn't any data on the computer...
sharedObject.data.highScore = nScore; // ...set the savedScore to 0
} else
{
trace("Save data found."); // if we did find data...
loadData(); // ...load the data
}
然后在 SAVEDATA();
功能,我有这样的:
Then in the saveData();
function I have this:
public function saveData():void
{
if (nScore > sharedObject.data.highScore )
{
sharedObject.data.highScore = nScore;
}
menuEnd.bestScore.text = " " + sharedObject.data.highScore;
sharedObject.flush();
//trace("Data Saved!");
//sharedObject.clear();
if (nScore == 10)
{
achiev_10 = new Achievment_10();
menuEnd.addChild(achiev_10);
achiev_10.x = stage.stageWidth / 2;
achiev_10.y = stage.stageHeight / 2;
sharedObject.flush();
}
}
现在目前在如果(NSCore公司== 10)
在这里我添加的影片剪辑,它的工作,它不会显示。但是,当我回去查我的影片剪辑的成就是自败。我真的不知道我需要做什么来保存数据,如果保存data.highscore等于10则始终显示这一成就。
Now currently in the if (nScore == 10)
where I add the Move Clip, it does work and it does display. But when i go back to check my Move Clip achievement it dissapears. I don't really know what i need to do to save the data if the save data.highscore is equal to 10 then always display that achievement.
我也试过,但没有什么:
I also tried this but nothing:
if (sharedObject.data.highScore == 10)
{
achiev_10 = new Achievment_10();
menuEnd.addChild(achiev_10);
achiev_10.x = stage.stageWidth / 2;
achiev_10.y = stage.stageHeight / 2;
sharedObject.flush();
}
请帮忙,谢谢!
推荐答案
您将需要几个函数与共享对象的工作。但是你应该知道,用户可以从共享对象明确的价值观,和成就将会丢失。
You will need several functions to work with SharedObject. But you should know, user can clear values from the SharedObject, and achievements will be lost.
private function getScore(key:String, domain:String):* {
try {
var so:SharedObject = SharedObject.getLocal(domain);
var data:Object = so.data;
if (key in data) {
return data[key];
} else {
trace(key + " doesn't present in SharedObject");
}
} catch (e:*) {
trace("Oops, something goes wrong…");
}
}
private function saveScore(value:*, key:String, domain:String):void {
try {
var so:SharedObject = SharedObject.getLocal(domain);
so.data[key] = value;
so.flush();
} catch (e:*) {
trace("Oops, something goes wrong…");
}
}
现在你可以用分数工作:
Now you can work with scores:
var domain:String = "GeometryBlast";
var scoreKey:String = "ScoreKey";
const newcomer: int = 10;
//Getting scores
var myScore: Number = getScore(scoreKey, domain);
//Simple example how you could manage score values
if(!isNaN(myScore)){
//Check achievements
if(myScore >= newcomer){
//Add 'Newcomer' achievement to the screen
}
}
//Saving scores
var someScores:Number = 10;
saveScore(someScores, scoreKey, domain);
相关推荐
最新文章