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.
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?