Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.events.Event;
- import flash.display.Loader;
- import flash.net.URLRequest;
- import flash.net.FileReference;
- import flash.net.URLLoader;
- import flash.net.SharedObject;
- //menu high scores
- btn_back.addEventListener(MouseEvent.MOUSE_UP, mouse_handler_menuhighscores);
- var highscores:SharedObject=SharedObject.getLocal("scores");
- addEventListener(Event.ENTER_FRAME,writeTxt);
- addEventListener(Event.ENTER_FRAME,onLoadTxt);
- function onLoadTxt(e:Event):void {
- if(highscores.data.nomeS1 && highscores.data.pontS1){
- first_txt.text = highscores.data.nomeS1;
- first_pont.text = highscores.data.pontS1;
- }
- if(highscores.data.nomeS2 && highscores.data.pontS2){
- second_txt.text = highscores.data.nomeS2;
- second_pont.text = highscores.data.pontS2;
- }
- if(highscores.data.nomeS3 && highscores.data.pontS3){
- third_txt.text = highscores.data.nomeS3;
- third_pont.text = highscores.data.pontS3;
- }
- if(highscores.data.nomeS4 && highscores.data.pontS4){
- fourth_txt.text = highscores.data.nomeS4;
- fourth_pont.text = highscores.data.pontS4;
- }
- if(highscores.data.nomeS5 && highscores.data.pontS5){
- fifth_txt.text = highscores.data.nomeS5;
- fifth_pont.text = highscores.data.pontS5;
- }
- if(highscores.data.nomeS6 && highscores.data.pontS6){
- sixth_txt.text = highscores.data.nomeS6;
- sixth_pont.text = highscores.data.pontS6;
- }
- if(highscores.data.nomeS7 && highscores.data.pontS7){
- seventh_txt.text = highscores.data.nomeS7;
- seventh_pont.text = highscores.data.pontS7;
- }
- if(highscores.data.nomeS8 && highscores.data.pontS8){
- eighth_txt.text = highscores.data.nomeS8;
- eighth_pont.text = highscores.data.pontS8;
- }
- if(highscores.data.nomeS9 && highscores.data.pontS9){
- nineth_txt.text = highscores.data.nomeS9;
- nineth_pont.text = highscores.data.pontS9;
- }
- if(highscores.data.nomeS10 && highscores.data.pontS10){
- tenth_txt.text = highscores.data.nomeS10;
- tenth_pont.text = highscores.data.pontS10;
- }
- }
- var nomes:Array = new Array("no","no","no"," no","no","no","no","no","no","no");
- var scores:Array = new Array(0,0,0,0,0,0,0,0,0,0);
- /*
- nomes[0]="utilizador1";
- scores[0]=0;
- nomes[1]= "utilizador2";
- scores[1]= 0;
- nomes[2]="utilizador3";
- scores[2]=0;
- nomes[3]="utilizador4";
- scores[3]=0;
- nomes[4]="utilizador5";
- scores[4]=0;
- nomes[5]="utilizador6";
- scores[5]=0;
- nomes[6]="utilizador7";
- scores[6]=0;
- nomes[7]="utilizador8";
- scores[7]=0;
- nomes[8]="utilizador9";
- scores[8]=0;
- nomes[9]="utilizador10";
- scores[9]=0;
- */
- var i: Number=0;
- var j: Number=0;
- var k: Number=0;
- var troca: Number = 0;
- var troca2: Number =0;
- var aux_pont:Number;
- var aux_name:String;
- var aux_pont2:Number;
- var aux_name2:String;
- var nome:String;
- var pontos:Number;
- function writeTxt(e:Event):void {
- cookiesOut();
- //recebe var nome e var pontos
- for(j=1;j<10;j++){
- if(scores[j-1]==0&&troca==0){
- scores[j]=pontos;
- nomes[j]=nome;
- troca=1;
- removeEventListener(Event.ENTER_FRAME,writeTxt);
- break;
- }
- }
- for(k=0;k<8;k++){
- if(pontos>scores[k]&&scores[k]!=0&&troca2==0){
- aux_pont=scores[k];
- aux_name=nomes[k];
- scores[k]=pontos;
- nomes[k]=nome;
- troca2=1;
- }
- if(troca2==1){
- aux_pont2=aux_pont;
- aux_pont=scores[k+1];
- scores[k+1]=aux_pont2;
- aux_name2=aux_name;
- aux_name=nomes[k+1];
- nomes[k+1]=aux_name2;
- }
- removeEventListener(Event.ENTER_FRAME,writeTxt);
- }
- troca=0;
- cookiesIn();
- highscores.flush();
- }
- function cookiesOut():void{
- nomes[0]=highscores.data.nomeS1;
- nomes[1]=highscores.data.nomeS2;
- nomes[2]=highscores.data.nomeS3;
- nomes[3]=highscores.data.nomeS4;
- nomes[4]=highscores.data.nomeS5;
- nomes[5]=highscores.data.nomeS6;
- nomes[6]=highscores.data.nomeS7;
- nomes[7]=highscores.data.nomeS8;
- nomes[8]=highscores.data.nomeS9;
- nomes[9]=highscores.data.nomeS10;
- scores[0]=highscores.data.pontS1;
- scores[1]=highscores.data.pontS2;
- scores[2]=highscores.data.pontS3;
- scores[3]=highscores.data.pontS4;
- scores[4]=highscores.data.pontS5;
- scores[5]=highscores.data.pontS6;
- scores[6]=highscores.data.pontS7;
- scores[7]=highscores.data.pontS8;
- scores[8]=highscores.data.pontS9;
- scores[9]=highscores.data.pontS10;
- }
- function cookiesIn():void{
- highscores.data.nomeS1=nomes[0];
- highscores.data.nomeS2=nomes[1];
- highscores.data.nomeS3=nomes[2];
- highscores.data.nomeS4=nomes[3];
- highscores.data.nomeS5=nomes[4];
- highscores.data.nomeS6=nomes[5];
- highscores.data.nomeS7=nomes[6];
- highscores.data.nomeS8=nomes[7];
- highscores.data.nomeS9=nomes[8];
- highscores.data.nomeS10=nomes[9];
- highscores.data.pontS1=scores[0];
- highscores.data.pontS2=scores[1];
- highscores.data.pontS3=scores[2];
- highscores.data.pontS4=scores[3];
- highscores.data.pontS5=scores[4];
- highscores.data.pontS6=scores[5];
- highscores.data.pontS7=scores[6];
- highscores.data.pontS8=scores[7];
- highscores.data.pontS9=scores[8];
- highscores.data.pontS10=scores[9];
- }
- function mouse_handler_menuhighscores(e:MouseEvent): void{
- switch(e.target.name)
- {
- case "btn_back":
- removeEventListener(Event.ENTER_FRAME,writeTxt);
- removeEventListener(Event.ENTER_FRAME,onLoadTxt);
- gotoAndStop(2);
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement