# Error playing a song from a xml file

**URL:** <https://forum.kirupa.com/t/error-playing-a-song-from-a-xml-file/252465>\
**Category:** flash\
**Created:** [February 20, 2008, 12:54pm UTC](https://forum.kirupa.com/t/error-playing-a-song-from-a-xml-file/252465 "2008-02-20T12:54:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecptavares](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@ecptavares](https://forum.kirupa.com/u/ecptavares)\
**Post date:** [February 20, 2008, 12:54pm UTC](https://forum.kirupa.com/t/error-playing-a-song-from-a-xml-file/252465/1 "2008-02-20T12:54:32Z")

</div>

Hi!  
I am trying to play some songs that have been loaded from a XML file.  
The XML file is loading everything write.The problem is that when I first run my movie it plays the sound correctly but when I click a button to play another song it stops playing(because I asked to stop) and gives me an error without play another song.

```auto

var xmlLoader : URLLoader = new URLLoader();
var url : URLRequest = new URLRequest("songs.xml");
var Songs :Array = new Array();
var xSongs :XML;

var slc :SoundLoaderContext = new SoundLoaderContext(3000);
var S :Sound = new Sound();
var SC :SoundChannel;

xmlLoader.load(url);
xmlLoader.addEventListener(Event.COMPLETE,onLoaded);

music1.addEventListener(MouseEvent.CLICK,onMusic1CLICK);
music2.addEventListener(MouseEvent.CLICK,onMusic2CLICK);

function onMusic1CLICK(e:MouseEvent):void
{
   playSong(0);
}

function onMusic2CLICK(e:MouseEvent):void
{
   playSong(1);
}

function onLoaded(event:Event):void
{
   xSongs = new XML(event.target.data);
   var lSongs :XMLList = xSongs.song.attribute("url");
   
   for each(var Lista:XML in lSongs){
      Songs.push(Lista);
   }
   
   playSong(1);
   music2.visible = false;
}

function playSong(songID : Number):void{

   SoundMixer.stopAll();
   S.load(new URLRequest(Songs[songID]),slc);
    SC = S.play();      
   SC.soundTransform = new SoundTransform(0.7);
}

```

and the error message

> 

Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.  
at flash.media::Sound/flash.media:Sound::\_load()  
at flash.media::Sound/load()  
at SITE2008\_fla::s\_34/playSong()  
at SITE2008\_fla::s\_34/onMusic1CLICK()

What is wrong with this code?
