A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: can't get more than one sound to play

  1. #1
    Senior Member
    Join Date
    Sep 2006
    Posts
    125

    can't get more than one sound to play

    Hi

    I am trying to build a simple xml based mp3 player for a project. I have got as far as combo/list boxes populating.

    The first time you click the a track to play it all is well.

    However, when you click another track, the first stops, but then I get error message.

    Here's the relevant code:

    Code:
    ar snd:Sound = new Sound();
    snd.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false,0,true);
    var channel:SoundChannel;
    var soundPlaying:Boolean = false;
    
    :
    :
    function playSong(e:Event):void{
    	if (soundPlaying==true){
    			channel.stop();
    			soundPlaying=false;
    		}
    	
    	var songURL:String = baseURL+album_cmb.selectedItem.label+"/"+songs_list.selectedItem.label;
    	snd.load(new URLRequest (songURL));
    	channel = snd.play();
    	soundPlaying=true;
    	
    	//trace ("soundPlaying="+soundPlaying);
    }
    I think something might be wrong with the way I am attempting to load in the second sound - but that analysis might be wrong of course!

    This is the error:

    Code:
    rror: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
    	at flash.media::Sound/_load()
    	at flash.media::Sound/load()
    	at MP3s002_fla::MainTimeline/playSong()
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    Any help greatfully received

    thanks

    E

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    You cannot use a Sound object to perform 2 load operations. One Sound can only load one..sound.

    PHP Code:
    function playSong (...) {
        ....
        var 
    snd:Sound = new Sound ();
        
    snd.load (new URLRequest (songURL));
        
    channel snd.play ();


  3. #3
    Senior Member
    Join Date
    Sep 2006
    Posts
    125
    thanks - works now!

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