A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Getting error when loading in new sound

  1. #1

    resolved [RESOLVED] Getting error when loading in new sound

    I'm working on improving the media player for my portfolio (www.robin.astedt.name) and I've run into a wall.. I can't figure out how to solve this one and I hope one of you could help me.

    The problem I get is that I can play songs and pause them and resume etc, but when I want to select another song and play it I get an error. It works if I initiate the Sound (s) and SoundChannel (sc) variables in the musicPlay(); function but then I can't pause because I need it to be initiated twice that way which ofcourse also gives me an error.

    Here's the error I get when I play another song:

    Code:
    Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
    	at flash.media::Sound/_load()
    	at flash.media::Sound/load()
    	at adv_music_fla::MainTimeline/musicPlay()
    	at adv_music_fla::MainTimeline/musicSelect()
    	at adv_music_fla::MainTimeline/musicPlaySong5()
    I don't really know that much about AS3 yet so maybe you could help me out here. Here's my code for the player:

    Code:
    mc_previous.buttonMode = true;
    mc_play.buttonMode = true;
    mc_pause.buttonMode = true;
    mc_stop.buttonMode = true;
    mc_next.buttonMode = true;
    var songMaxNumber:Number = 8;
    var songLoop:Boolean = true;
    var slc:SoundLoaderContext = new SoundLoaderContext(2000);
    var songNumber:Number = 1;
    var songTempNumber:Number = 1;
    var songURL:String = "music/nightmare.mp3";
    var songIsPlaying:Boolean = false;
    var songButton = mc_playlist.mc_play_song1
    var songPausePos:Number = new Number();
    var songPaused:Boolean = false;
    var s:Sound = new Sound();
    var sc:SoundChannel = new SoundChannel();
    
    mc_playlist.mc_play_song1.addEventListener(MouseEvent.CLICK, musicPlaySong1);
    function musicPlaySong1(event:MouseEvent):void
    {
    	musicSelect(1);
    }
    mc_playlist.mc_play_song2.addEventListener(MouseEvent.CLICK, musicPlaySong2);
    function musicPlaySong2(event:MouseEvent):void
    {
    	musicSelect(2);
    }
    mc_playlist.mc_play_song3.addEventListener(MouseEvent.CLICK, musicPlaySong3);
    function musicPlaySong3(event:MouseEvent):void
    {
    	musicSelect(3);
    }
    mc_playlist.mc_play_song4.addEventListener(MouseEvent.CLICK, musicPlaySong4);
    function musicPlaySong4(event:MouseEvent):void
    {
    	musicSelect(4);
    }
    mc_playlist.mc_play_song5.addEventListener(MouseEvent.CLICK, musicPlaySong5);
    function musicPlaySong5(event:MouseEvent):void
    {
    	musicSelect(5);
    }
    mc_playlist.mc_play_song6.addEventListener(MouseEvent.CLICK, musicPlaySong6);
    function musicPlaySong6(event:MouseEvent):void
    {
    	musicSelect(6);
    }
    mc_playlist.mc_play_song7.addEventListener(MouseEvent.CLICK, musicPlaySong7);
    function musicPlaySong7(event:MouseEvent):void
    {
    	musicSelect(7);
    }
    mc_playlist.mc_play_song8.addEventListener(MouseEvent.CLICK, musicPlaySong8);
    function musicPlaySong8(event:MouseEvent):void
    {
    	musicSelect(8);
    }
    mc_previous.addEventListener(MouseEvent.CLICK, musicButtonPrevious);
    function musicButtonPrevious(event:MouseEvent):void
    {
    	if (songNumber>1) {
    		musicSelect(songNumber-1);
    	}
    	else {
    		musicSelect(songMaxNumber);
    	}
    }
    mc_play.addEventListener(MouseEvent.CLICK, musicButtonPlay);
    function musicButtonPlay(event:MouseEvent):void
    {
    	musicPlay(songURL, songNumber, songButton);
    }
    mc_pause.addEventListener(MouseEvent.CLICK, musicButtonPause);
    function musicButtonPause(event:MouseEvent):void
    {
    	musicPlay(songURL, 0, songButton);
    }
    mc_stop.addEventListener(MouseEvent.CLICK, musicButtonStop);
    function musicButtonStop(event:MouseEvent):void
    {
    	musicPlay(songURL, -1, songButton);
    }
    mc_next.addEventListener(MouseEvent.CLICK, musicButtonNext);
    function musicButtonNext(event:MouseEvent):void
    {
    	if (songNumber<songMaxNumber) {
    		musicSelect(songNumber+1);
    	}
    	else {
    		musicSelect(1);
    	}
    }
    
    function musicSelect(songSelect) {
    	if (songSelect==1) {
    		musicPlay("music/nightmare.mp3", 1, mc_playlist.mc_play_song1);
    	}
    	else if (songSelect==2) {
    		musicPlay("music/disable_all.mp3", 2, mc_playlist.mc_play_song2);
    	}
    	else if (songSelect==3) {
    		musicPlay("music/settling_sun.mp3", 3, mc_playlist.mc_play_song3);
    	}
    	else if (songSelect==4) {
    		musicPlay("music/nevertheless.mp3", 4, mc_playlist.mc_play_song4);
    	}
    	else if (songSelect==5) {
    		musicPlay("music/victory.mp3", 5, mc_playlist.mc_play_song5);
    	}
    	else if (songSelect==6) {
    		musicPlay("music/uprise.mp3", 6, mc_playlist.mc_play_song6);
    	}
    	else if (songSelect==7) {
    		musicPlay("music/submission.mp3", 7, mc_playlist.mc_play_song7);
    	}
    	else if (songSelect==8) {
    		musicPlay("music/contempt.mp3", 8, mc_playlist.mc_play_song8);
    	}
    	
    }
    
    
    function musicPlay(songTempURL, songTempNumber, songTempButton) {
    	
    	
    	if (songTempNumber == 0) {
    		if (songIsPlaying==true) {
    			songURL=songTempURL;
    			songButton=songTempButton;
    			
    			if (songPaused==false) {
    				SoundMixer.stopAll();
    				songPaused=true;
    				songPausePos=sc.position;
    				mc_pause.gotoAndStop(2);
    			}
    			else {
    				songPaused=false;
    				sc = s.play(songPausePos);
    				mc_pause.gotoAndStop(1);
    			}
    			
    			trace("pause");
    			trace(songTempNumber);
    			trace(songNumber);
    			trace(songURL);
    			trace(songButton);
    			trace(songPaused);
    		}
    	}
    	else if (songTempNumber == -1) {
    		songButton=songTempButton
    		songButton.gotoAndStop(1);
    		songURL=songTempURL;
    		songIsPlaying=false;
    		songPausePos=0;
    		songPaused=false;
    		mc_pause.gotoAndStop(1);
    		SoundMixer.stopAll();
    		trace("stop");
    		trace(songTempNumber);
    		trace(songNumber);
    		trace(songURL);
    		trace(songButton);
    	}
    	else if (songTempNumber != songNumber || songIsPlaying==false) {
    		
    		songButton.gotoAndStop(1);
    		songTempButton.gotoAndStop(2);
    		songButton=songTempButton
    		songNumber=songTempNumber
    		songURL=songTempURL;
    		songIsPlaying=true;
    		SoundMixer.stopAll();
    		s.load(new URLRequest(songURL), slc)
    		sc = s.play(songPausePos);
    		sc.addEventListener(Event.SOUND_COMPLETE, musicComplete);
    		trace("play");
    		trace(songTempNumber);
    		trace(songNumber);
    		trace(songURL);
    		trace(songButton);
    	}
    	else if (songPaused==true) {
    		songPaused=false;
    		sc = s.play(songPausePos);
    		mc_pause.gotoAndStop(1);
    	}
    	
    }
    
    function musicComplete() {
    	if (songNumber<songMaxNumber) {
    		musicSelect(songNumber+1);
    	}
    	else if (songLoop==true) {
    		musicSelect(1);
    	}
    	else {
    		musicPlay(songURL, -1, songButton);
    	}
    }
    Last edited by HolyGarbage; 05-13-2009 at 11:59 AM. Reason: Added error-message

  2. #2

    Exclamation

    Problem sovled. An admin may close this thread.

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Thread Tools >> Mark Thread Resolved

  4. #4
    ok, thank you.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center