PDA

View Full Version : Interactive Sound Game


LJD
02-10-2009, 08:41 PM
Hi. Apologies if this has already been covered it's just Iím not entirely sure what I need to do so was unsure of what to search for.

The game is composed of a scene that contains buttons that play different sounds when pressed. The user clicks a button, 'record', which records the sequence in which they press the buttons and they can then play their sequence back using a 'play' button.

I understand I need to use an array to do this but how I would go about this is what I am lost about. I hope I have been clear enough on my description and any help would be greatly appreciated.

Thanks.

neilmmm
02-10-2009, 10:45 PM
something like
var soundArray:Array = new Array();
var s:Sound = new Sound();
var counter:Number = 0;
var soundLength:Number = 0;
s1_mc.onRelease = function() {
s.attachSound("s1");
s.start();
soundArray.push("s1");
};
s2_mc.onRelease = function() {
s.attachSound("s2");
s.start();
soundArray.push("s2");
};
s3_mc.onRelease = function() {
s.attachSound("s3");
s.start();
soundArray.push("s3");
};
clear_mc.onRelease = function() {
soundArray = [];
};
function playSounds() {
soundLength = soundArray.length;
if (counter<soundArray.length) {
s.attachSound(soundArray[counter]);
s.start();
counter++;
s.onSoundComplete = playSounds;
} else {
counter = 0;
delete s.onSoundComplete;
}
}
play_mc.onRelease = function() {
playSounds();
};
s1_mc.inner_txt.text = "sound 1";
s2_mc.inner_txt.text = "sound 2";
s3_mc.inner_txt.text = "sound 3";
clear_mc.inner_txt.text = "clear";
play_mc.inner_txt.text = "play";