-
Notifications
You must be signed in to change notification settings - Fork 1
/
SecondoGioco.as
executable file
·277 lines (212 loc) · 8.92 KB
/
SecondoGioco.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package {
import flash.display.*;
import flash.text.*;
import flash.media.*;
import flash.net.*;
import flash.utils.Timer; // timer
import flash.events.Event; // ATTENZIONE
import flash.events.TimerEvent; // timer
import flash.events.MouseEvent;
import id.core.Application;
import id.core.TouchSprite;
import id.core.ApplicationGlobals;
import gl.events.TouchEvent;
import caurina.transitions.*;
public class SecondoGioco extends TouchSprite {
/***********************************************************/
/** variabili **********************************************/
// sfondo
//private var tile:Background = new Background(new Material05(0,0));
// index array
private var index:int;
// this
var thisGioco = this;
// array per contenitori e musica
private var containerArray:Array;
private var mp3Array:Array;
private var mp3EffettiArray:Array;
private var funzioniArray:Array;
private var pulsantiArray:Array;
private var channelArray:Array;
// container
var BIG_container = new TouchSprite();
var container_button_home = new TouchSprite();
var container_screen_saver = new TouchSprite();
var container_01 = new TouchSprite();
var container_02 = new TouchSprite();
var container_03 = new TouchSprite();
var container_04 = new TouchSprite();
var container_05 = new TouchSprite();
var container_06 = new TouchSprite();
var container_07 = new TouchSprite();
var container_08 = new TouchSprite();
var container_09 = new TouchSprite();
var container_10 = new TouchSprite();
var container_11 = new TouchSprite();
// suoni
var channel01:SoundChannel = new SoundChannel();
var channel02:SoundChannel = new SoundChannel();
var channel03:SoundChannel = new SoundChannel();
var channel04:SoundChannel = new SoundChannel();
var channel05:SoundChannel = new SoundChannel();
var channel06:SoundChannel = new SoundChannel();
var channel07:SoundChannel = new SoundChannel();
var channel08:SoundChannel = new SoundChannel();
var channel09:SoundChannel = new SoundChannel();
var channel10:SoundChannel = new SoundChannel();
var channel11:SoundChannel = new SoundChannel();
// timer
var timerScreen:int = 300000;
var timer = new Timer(timerScreen, 1);
/*************************************************************/
/** costruttore **********************************************/
public function SecondoGioco() {
addEventListener(Event.ADDED_TO_STAGE, addedHandler);
addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
}
private function addedHandler(event:Event):void {
mp3EffettiArray = ["sceltagioco.mp3"];
containerArray = [container_01, container_02, container_03, container_04, container_05, container_06, container_07,
container_08, container_09, container_10, container_11];
mp3Array = ["chitarra.mp3", "tromba.mp3", "fagotto.mp3", "siringa.mp3", "violino.mp3",
"tuba.mp3", "drumroll.mp3", "corno.mp3", "clarinetto.mp3", "sax.mp3","flauto.mp3"];
pulsantiArray = [musicButton01, musicButton02, musicButton03, musicButton04, musicButton05,
musicButton06, musicButton07, musicButton08, musicButton09, musicButton10, musicButton11];
channelArray = [channel01, channel02, channel03, channel04, channel05, channel06, channel07, channel08, channel09, channel10, channel11];
trace("### Schermata --> Secondo Gioco aggiunta");
//this.x = (stage.stageWidth - this.width) ;
//this.y = (stage.stageHeight - this.height) ;
// ***********************************
// pulsanti --> screen
container_screen_saver.addChild(screensaver);
container_screen_saver.addEventListener(TouchEvent.TOUCH_DOWN,screenSaver);
addChild(container_screen_saver);
timer.addEventListener(TimerEvent.TIMER, onTimerFacce );
function onTimerFacce(evt:TimerEvent):void
{
var e:Event = new Event('gotoHome');
dispatchEvent(e);
}
timer.start();
// ***********************************
// pulsante --> home
container_button_home.addChild(button_Home);
container_button_home.addEventListener(TouchEvent.TOUCH_TAP,gotoHome);
addChild(container_button_home);
// ***********************************
// pulsante --> strumenti
for(var i:int = 0; i < containerArray.length; i++) {
this.x = 0;
//this.sfondoRiferimento.width = stage.stageWidth;
containerArray[i].addChild(pulsantiArray[i]);
containerArray[i].addEventListener(TouchEvent.TOUCH_DOWN, playSound);
containerArray[i].addEventListener(TouchEvent.TOUCH_DOWN, screenSaver);
//pulsantiArray[i].y = (this.height-pulsantiArray[i].height)/2 + 230;
//pulsantiArray[i].x = i*150;
//Tweener.addTween(pulsantiArray[i],{x: i*130,time:1.2,transition:"easeoutelastic"});
//Tweener.addTween(pulsantiArray[i],{y: ((stage.stageHeight-pulsantiArray[i].height)/2),time:1,transition:"easeoutelastic"});
addChild(containerArray[i]);
trace("Container x: " + containerArray[i].x);
trace("Stage height: " + stage.stageHeight);
trace("Pulsanti Array height: " + pulsantiArray[i].height);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function removedHandler(event:Event):void {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
/********************************************************/
/** metodi **********************************************/
// onenterframe sposto i pulsanti con la banda
private function onEnterFrame(event:Event):void {
//trace(sfondoRiferimento.width);
/*
citta01.x -= 1;
citta02.x -= 1;
*/
/*
if(citta01.x < -1024){
citta01.x = 1020;
}
if(citta02.x < -1024){
citta02.x = 1020;
}
/*
for(var i:int = 0; i < pulsantiArray.length; i++) {
//trace("pulsanti y: " + pulsantiArray[i].y);
//trace("pulsanti x: " + pulsantiArray[i].x);
var x_max:Number = 150*8; // x massima contando 8 personaggi
//trace("X MAX: " + x_max);
if (pulsantiArray[i].x > x_max) {
trace("i: " + i + " " + pulsantiArray[i].x);
var indexSpostamento:int;
if(i!=10) {
indexSpostamento = i + 1;
}
else {
indexSpostamento = i-10;
//trace("i = 10: " + indexSpostamento);
}
//trace("INDEX: " +indexSpostamento + pulsantiArray[i]);
pulsantiArray[i].x = Math.round(pulsantiArray[indexSpostamento].x) - 150;
}
pulsantiArray[i].x += 1.5;
}
*/
}
// torna a home
private function gotoHome(event:TouchEvent):void {
trace("# Evento --> Attivazione Home");
// fermo tutti i suoni
for(var i:int = 0; i < pulsantiArray.length; i++) {
channelArray[i].stop();
}
var e:Event = new Event('gotoHome');
dispatchEvent(e);
var channel:SoundChannel = new SoundChannel();
var audioMp3 = mp3EffettiArray[0];
var mysound:Sound = new Sound(); /* IMPORTANTE */
mysound.load(new URLRequest("suoni/effetti/" + audioMp3));
channel = mysound.play(0);
timer.stop();
}
private function screenSaver(e:TouchEvent):void {
timer.reset();
timer.start();
}
private function onSoundComplete(event:Event):void{
trace("prova");
index = channelArray.indexOf(event.target);
trace("INDEX ARRAY: " + index);
containerArray[index].getChildAt(0).scaleX = 0.85;
containerArray[index].getChildAt(0).scaleY = 0.85;
containerArray[index].addEventListener(TouchEvent.TOUCH_DOWN, playSound);
}
// suona lo strumento scelto
private function playSound(event:TouchEvent):void
{
index = containerArray.indexOf(event.target);
trace("INDEX ARRAY: " + index);
/*
Tweener.addTween(event.target.getChildAt(0),{scaleX:1.03,time:0.3,transition:"easeOutQuart", onComplete:func});
Tweener.addTween(event.target.getChildAt(0),{scaleY:1.03,time:0.3,transition:"easeOutQuart"});
function func() {
Tweener.addTween(event.target.getChildAt(0),{scaleX:0.85,time:0.2,transition:"easeInQuart"});
Tweener.addTween(event.target.getChildAt(0),{scaleY:0.85,time:0.2,transition:"easeInQuart"});
}
*/
event.target.getChildAt(0).scaleX = 1.03;
event.target.getChildAt(0).scaleY = 1.03;
trace("Sprite CLICCATO: " + event.target.name);
trace("Gioco CLICCATO: " + event.target.parent.name);
channelArray[index].stop();
var audioMp3 = mp3Array[index];
var mysound:Sound = new Sound(); /* IMPORTANTE */
mysound.load(new URLRequest("suoni/strumenti/" + audioMp3));
channelArray[index] = mysound.play(0);
//trace(mysound.length);
containerArray[index].removeEventListener(TouchEvent.TOUCH_DOWN, playSound);
channelArray[index].addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
}
}
}