I have a movie clip called player where there is a code to pull a background music through an xml file. In the same movie clip, there is play and pause controls. Here's the code:
Actionscript Code:
stop();
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("playlist.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_songs = myXML.SONG;
my_total = my_songs.length();
playSong(0);
myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader = null;
}
function playSong(mySong:Number):void {
var myURL = my_songs[mySong].@URL;
if (my_channel) {
my_channel.stop();
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
}
pausar.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {
music_bars.stop();
if (my_channel) {
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
}
tocar.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {
music_bars.play();
if (song_paused) {
my_channel = my_sound.play(song_position);
song_paused=false;
} else if (!my_channel) {
playSong(current_song);
}
}
I put this movie clip in the first scene and the music continues when I change the scene. So far so good. But if I put the movie clip in the other scenes, to control the music on the scene, the music resumed and the first music never stops.
How can I fix this?