Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MP3 Player, multiple functions per button, help needed

    Hi everyone, this is my first post and my first time working with actionscript. I'm developing a website for my own business and am integrating an mp3 player. I can have it play one song easily and I can have it go to the next song as well, however I can't pause and then re-play the second song because the button is linked to the first song. Here's what I have:

    Code:
    var music:Sound = new Sound(new URLRequest("http..."));
    var sc:SoundChannel = null;
    var isPlaying:Boolean = false;
    var pos:Number =0;
    var soundVolume:Number = 1;
    
    play_btn.buttonMode = true;
    pause_btn.buttonMode = true;
    
    play_btn.addEventListener(MouseEvent.CLICK, playMusic);
    pause_btn.addEventListener(MouseEvent.CLICK, pauseMusic);
    
    function playMusic(e:Event):void
    {
    			sc=music.play(pos);
    			isPlaying=true;		
    			dyn_txt.text="song1";
    		}
    		
    		
    function pauseMusic(evt:MouseEvent)
    {
    	pos = sc.position;
    			sc.stop();
    			isPlaying=false;
    			dyn_txt.text="song1";
    			soundVolume = 75;			
    		}
    
    var black:Sound = new Sound(new URLRequest("http..."));
    var sc2:SoundChannel = null;
    var isPlaying2:Boolean = false;
    var pos2:Number =0;
    var soundVoulmer2:Number = 1;
    
    next_btn.buttonMode = true;
    
    next_btn.addEventListener(MouseEvent.CLICK, nextBlack);
    
    function nextBlack(e:Event):void
    {
    	sc.stop();
    	sc2=black.play(pos);
    	isPlaying2=true;
    	dyn_txt.text="song2";
    }
    Any ideas?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I think the problem is you are creating separate functions and markers for different songs. You might consider this tutorial or something similar.

    http://www.flashessential.com/archives/26

    Ideally, you have an array with your songs listed, and you play songs based on an index variable that keeps track of what song you are on.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •