Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 135144

Re: Use actionscript to trigger independant sound loop and reset

$
0
0

Is it possible, with flash to put different sounds triggered by a set of a buttons into a track and play this track in a loop ?

 

I want to make it so when you press for example buttons A, then B, then C, it will play the sounds A, B and C respectively in an infinite loop. So when you click A, B, C, D, E, it will play ABCDE.

 

EDIT: I succeeded ! I had to use arrays to do that. But now I would like that instead of putting the sounds automatically into the array at the beginning (red part), I want to be able to put by clicking on different buttons. It means if I click "A" first it will put the A into index 0, then B and put into index 1, then C and put into index 2, and so on. How can ?

 

 

 

var musicTrack = new Array();

var aNote:a = new a();

var bNote:b = new b();

 

musicTrack.push(aNote);

musicTrack.push(bNote);

musicTrack.push(aNote);

 

 

var musicChannel:SoundChannel;

 

var currentSongIndex:int;

 

function  onPlayBtnPressed() {

  currentSongIndex = 0;

  playSongFromIndex(currentSongIndex);

}

 

 

 

 

function playSongFromIndex(songIndex:int) {

  musicChannel = musicTrack[songIndex].play();

  musicChannel.addEventListener(Event.SOUND_COMPLETE, songFinished);

  currentSongIndex++;

}

 

 

function songFinished(e:Event) {

  if (currentSongIndex < musicTrack.length) {

       playSongFromIndex(currentSongIndex);

  } else  {

       currentSongIndex=0;

  }

}

 

 

 

 

 

onPlayBtnPressed();


Viewing all articles
Browse latest Browse all 135144

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>