| resin |
07-06-2012 08:43 AM |
script help?
Hello, I have this script, which allows for multiple songs to play. I just need to get it working with my graphical interface, which is just simply a play/pause button. But I'm having trouble getting the script (SongPlayer.as) to work with my button.
Code:
package
{
import flash.display.*;
import flash.media.*;
import flash.events.*;
public class SongPlayer extends Sprite
{
private var s:Sound;
private var sc:SoundChannel;
private var isPlaying:Boolean;
private var songs:Array;
public function SongPlayer()
{
songs = [Song1,
Song2,
Song3,
Song4,
Song5];
playSong();
}
private function playSong():void
{
var index:int = Math.floor(Math.random() * songs.length);
s = new songs[index]() as Sound;
sc = new SoundChannel();
sc = s.play(0,0);
sc.addEventListener(Event.SOUND_COMPLETE, songComplete);
songs.splice(index, 1);
trace(s);
}
private function songComplete(e:Event):void
{
sc.stop();
if(songs.length > 0)
{
playSong();
}
else
{
trace("all songs played");
}
}
}
}
Like I said I just need this to work with a simple play/pause button, which I already have set up, I just need to tie it with this script. Also, I want the music to auto-play on load and to continue playing through all the songs without ever stopping. But I still want the option to pause playback (by clicking button) and then resume playback where it left off (by clicking button again). Any ideas?
|