Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2012, 08:43 AM   PM User | #1
resin
Regular Coder

 
Join Date: Nov 2011
Posts: 142
Thanks: 5
Thanked 0 Times in 0 Posts
resin is an unknown quantity at this point
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?
resin is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:20 PM.


Advertisement
Log in to turn off these ads.