actionscript 3 - How to display Movie Clip if shared Object is equal to a number AS3 -


hey i've been trying ti accomplish no success how display movie clip object named achiev_10 when nscore number equal 10.

here have far in shared object data.

in constructor have this:

//initialize our shared object give path save local data         sharedobject = sharedobject.getlocal("geometryblast");           if (sharedobject.data.highscore == null)          {                     // checks if there save data                trace("no saved data yet."); // if there isn't data on computer...                sharedobject.data.highscore = nscore; // ...set savedscore 0          } else           {                trace("save data found."); // if did find data...                loaddata(); // ...load data          } 

then in savedata(); function 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();         }      } 

now in if (nscore == 10) add move clip, work , display. when go check move clip achievement dissapears. don't know need save data if save data.highscore equal 10 display achievement.

i tried 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();     } 

please thank you!

you need several functions work sharedobject. should know, user can clear values sharedobject, , achievements 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, 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, goes wrong…");     } } 

now can work scores:

var domain:string = "geometryblast"; var scorekey:string = "scorekey"; const newcomer: int = 10;  //getting scores var myscore: number = getscore(scorekey, domain);  //simple example how manage score values if(!isnan(myscore)){     //check achievements      if(myscore >= newcomer){         //add 'newcomer' achievement screen     } }  //saving scores var somescores:number = 10; savescore(somescores, scorekey, domain); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -