View difference between Paste ID: Kjz7aJnX and q9Rz2nJJ
SHOW: | | - or go back to the newest paste.
1
import flash.events.Event;
2
import flash.display.Loader;
3
import flash.net.URLRequest;
4
import flash.net.FileReference;
5
import flash.net.URLLoader;
6
import flash.net.SharedObject;
7
//menu high scores
8
9
      
10
11
btn_back.addEventListener(MouseEvent.MOUSE_UP, mouse_handler_menuhighscores);
12
13
var highscores:SharedObject=SharedObject.getLocal("scores");
14
addEventListener(Event.ENTER_FRAME,writeTxt);
15
addEventListener(Event.ENTER_FRAME,onLoadTxt);
16
17
function onLoadTxt(e:Event):void {
18
	if(highscores.data.nomeS1 && highscores.data.pontS1){
19
		
20
	   	first_txt.text = highscores.data.nomeS1;
21
	   	first_pont.text = highscores.data.pontS1;
22
	}
23
	if(highscores.data.nomeS2 && highscores.data.pontS2){
24
		second_txt.text = highscores.data.nomeS2;
25
		second_pont.text = highscores.data.pontS2;
26
	}
27
	if(highscores.data.nomeS3 && highscores.data.pontS3){
28
		third_txt.text = highscores.data.nomeS3;
29
		third_pont.text = highscores.data.pontS3;
30
	}
31
	if(highscores.data.nomeS4 && highscores.data.pontS4){
32
		fourth_txt.text = highscores.data.nomeS4;
33
		fourth_pont.text = highscores.data.pontS4;
34
	}
35
	if(highscores.data.nomeS5 && highscores.data.pontS5){
36
		fifth_txt.text = highscores.data.nomeS5;
37
		fifth_pont.text = highscores.data.pontS5;
38
	}
39
	if(highscores.data.nomeS6 && highscores.data.pontS6){
40
		sixth_txt.text = highscores.data.nomeS6;
41
		sixth_pont.text = highscores.data.pontS6;
42
	}
43
	if(highscores.data.nomeS7 && highscores.data.pontS7){
44
		seventh_txt.text = highscores.data.nomeS7;
45
		seventh_pont.text = highscores.data.pontS7;
46
	}
47
	if(highscores.data.nomeS8 && highscores.data.pontS8){
48
		eighth_txt.text = highscores.data.nomeS8;
49
		eighth_pont.text = highscores.data.pontS8;
50
	}
51
	if(highscores.data.nomeS9 && highscores.data.pontS9){
52
		nineth_txt.text = highscores.data.nomeS9;
53
		nineth_pont.text = highscores.data.pontS9;
54
	}
55
	if(highscores.data.nomeS10 && highscores.data.pontS10){
56
		tenth_txt.text = highscores.data.nomeS10;
57
		tenth_pont.text = highscores.data.pontS10;
58
	}
59
	
60
}
61
var nomes:Array = new Array("no","no","no"," no","no","no","no","no","no","no");
62
var scores:Array = new Array(0,0,0,0,0,0,0,0,0,0);
63-
/*nomes[1] = "nome";
63+
/*
64-
scores[1] = 7;
64+
nomes[0]="utilizador1";
65-
scores[0]=8;
65+
scores[0]=0;
66-
nomes[0]="ola";
66+
nomes[1]= "utilizador2";
67-
nomes[2]="ines toto";
67+
scores[1]= 0;
68-
scores[2]=6;
68+
nomes[2]="utilizador3";
69-
nomes[3]="ines toto";
69+
scores[2]=0;
70-
scores[3]=5;
70+
nomes[3]="utilizador4";
71-
nomes[4]="ines tottoo";
71+
scores[3]=0;
72-
scores[4]=4;
72+
nomes[4]="utilizador5";
73-
nomes[5]="ines tototo";
73+
scores[4]=0;
74-
scores[5]=3;
74+
nomes[5]="utilizador6";
75-
nomes[6]="ines totototo";
75+
scores[5]=0;
76-
scores[6]=2;
76+
nomes[6]="utilizador7";
77-
nomes[7]="ines tototorrr";
77+
scores[6]=0;
78-
scores[7]=1;
78+
nomes[7]="utilizador8";
79-
nomes[8]="ines totrrrrr";
79+
scores[7]=0;
80-
scores[8]=1;
80+
nomes[8]="utilizador9";
81-
nomes[9]="ines totoww";
81+
scores[8]=0;
82-
scores[9]=1;*/
82+
nomes[9]="utilizador10";
83
scores[9]=0;
84
*/
85
86
var i: Number=0;
87
var j: Number=0;
88
var k: Number=0;
89
var troca: Number = 0;
90
var troca2: Number =0;
91
var aux_pont:Number;
92
var aux_name:String;
93
var aux_pont2:Number;
94
var aux_name2:String;
95
96
var nome:String;
97
var pontos:Number;
98
99
function writeTxt(e:Event):void {
100
	cookiesOut();
101
	//recebe var nome e var pontos
102
	for(j=1;j<10;j++){
103
		
104
		if(scores[j-1]==0&&troca==0){
105
			scores[j]=pontos;
106
			nomes[j]=nome;
107
			
108
			troca=1;
109
			
110
			removeEventListener(Event.ENTER_FRAME,writeTxt);
111
			break;
112
		}
113
	}
114
	for(k=0;k<8;k++){
115
		if(pontos>scores[k]&&scores[k]!=0&&troca2==0){
116
117
			aux_pont=scores[k];
118
			aux_name=nomes[k];
119
			scores[k]=pontos;
120
			nomes[k]=nome;
121
			troca2=1;
122
			
123
		}
124
		if(troca2==1){
125
			aux_pont2=aux_pont;
126
			aux_pont=scores[k+1];
127
			scores[k+1]=aux_pont2;
128
			
129
			aux_name2=aux_name;
130
			aux_name=nomes[k+1];
131
			nomes[k+1]=aux_name2;
132
			
133
		}
134
		removeEventListener(Event.ENTER_FRAME,writeTxt);
135
	}
136
	troca=0;
137
138
	cookiesIn();
139
	
140
	highscores.flush();
141
}
142
function cookiesOut():void{
143
	nomes[0]=highscores.data.nomeS1;
144
	nomes[1]=highscores.data.nomeS2;
145
	nomes[2]=highscores.data.nomeS3;
146
	nomes[3]=highscores.data.nomeS4;
147
	nomes[4]=highscores.data.nomeS5;
148
	nomes[5]=highscores.data.nomeS6;
149
	nomes[6]=highscores.data.nomeS7;
150
	nomes[7]=highscores.data.nomeS8;
151
	nomes[8]=highscores.data.nomeS9;
152
	nomes[9]=highscores.data.nomeS10;
153
	scores[0]=highscores.data.pontS1;
154
	scores[1]=highscores.data.pontS2;
155
	scores[2]=highscores.data.pontS3;
156
	scores[3]=highscores.data.pontS4;
157
	scores[4]=highscores.data.pontS5;
158
	scores[5]=highscores.data.pontS6;
159
	scores[6]=highscores.data.pontS7;
160
	scores[7]=highscores.data.pontS8;
161
	scores[8]=highscores.data.pontS9;
162
	scores[9]=highscores.data.pontS10;
163
}
164
function cookiesIn():void{
165
	highscores.data.nomeS1=nomes[0];
166
	highscores.data.nomeS2=nomes[1];
167
	highscores.data.nomeS3=nomes[2];
168
	highscores.data.nomeS4=nomes[3];
169
	highscores.data.nomeS5=nomes[4];
170
	highscores.data.nomeS6=nomes[5];
171
	highscores.data.nomeS7=nomes[6];
172
	highscores.data.nomeS8=nomes[7];
173
	highscores.data.nomeS9=nomes[8];
174
	highscores.data.nomeS10=nomes[9];
175
	highscores.data.pontS1=scores[0];
176
	highscores.data.pontS2=scores[1];
177
	highscores.data.pontS3=scores[2];
178
	highscores.data.pontS4=scores[3];
179
	highscores.data.pontS5=scores[4];
180
	highscores.data.pontS6=scores[5];
181
	highscores.data.pontS7=scores[6];
182
	highscores.data.pontS8=scores[7];
183
	highscores.data.pontS9=scores[8];
184
	highscores.data.pontS10=scores[9];
185
}
186
187
188
function mouse_handler_menuhighscores(e:MouseEvent): void{
189
	switch(e.target.name)
190
	{
191
		
192
		case "btn_back":
193
				
194
				removeEventListener(Event.ENTER_FRAME,writeTxt);
195
				removeEventListener(Event.ENTER_FRAME,onLoadTxt);
196
				gotoAndStop(2);
197
				break;
198
		default:
199
				break;
200
	}
201
}