-
[RESOLVED] [CS3] mp3 player swf keeps playing when go to other pages
I went to a tutorial site to create an mp3 player. On my website, I want to load the mp3 player as a swf file, which the original action script code was not designed for. I made changes to the action script, so the mp3 player would play when the swf file was loaded onto my site and ran into another problem. If the mp3 player is left playing, when you go to another page on my site, the music won't stop. I am using a shell based site, so each page is a separate swf file. Is there a way to make it so that when a new swf file is loaded, the music will stop? The actionscript to make the player work is below(where I made changes, the original code is preceded by // with my action script below):
PHP Code:
stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
}
}
// _root.createEmptyMovieClip("sound_mc", 1);
createEmptyMovieClip("sound_mc", 1);
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = 0;
};
function timer(sound_obj) {
time = sound_obj.position/1000;
min = Math.floor(time/60);
min = (min<10) ? "0"+min : min;
sec = Math.floor(time%60);
sec = (sec<10) ? "0"+sec : sec;
timeDisplay_txt.text = min+":"+sec;
}
MovieClip.prototype.songStarter = function(file, name, band) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
//this._parent.display_txt.text = name+" / "+band;
display_txt.text = name+" / "+band;
timeInterval = setInterval(timer, 1000, this.sound_obj);
} else {
this._parent.display_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
};
//this._parent.volume1.dragger.onPress = function() {
volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume(p);
};
};
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
this._parent.volume1.dragger.onReleaseOutside = function() {
stopDrag();
};
};
btn_play.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
gotoAndStop("play");
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
gotoAndStop("play");
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
gotoAndStop("play");
};
playlist.load("playlist.xml");
Last edited by Rebstone; 05-20-2008 at 12:01 PM.
Reason: php
-
Bmcc*81
Hi,
If you load it up through loadMovie then you should be able to unloadMovie on your buttons.
Code:
on (press) {
unloadMovieNum (4);
}
or through
Code:
yourButton.onRelease = functions() {
unloadMovie(1);
}
unloadMovie(1); will unload level 1
Just find the level that the Mp3 player is on and unload that level.
-
I don't have a whole lot of experience with Flash, so I have a very basic question, how do you figure out which level your movie is being loaded on to? To complicate matters, I have a button in my main site loading a graphic design swf file using the following code:
PHP Code:
on(release)
{
_root.loader_mc.loadMovie("GraphicDesign.swf");
}
In the graphic design swf, I have another button that is loading my mp3 player swf, which uses the code below:
PHP Code:
Mp3.onRelease=function(){
gotoAndStop(7);
loader_mc3.loadMovie("mp3Player_part2.swf")
with (loader_mc3){
_xscale=70
_yscale=70
}
}
I tried experimenting with unloading the movie using both of the suggested ways, but I couldn't figure out how to make it work correctly. I tried putting in random level #'s, but the only thing that did anything was putting in level 0, and that cleared everything, so there was only a white screen.
-
Bmcc*81
Hi,
So basically this means:
Code:
_root.loader_mc.loadMovie("GraphicDesign.swf");
_root. there bottom of flash = _level1
When you see loader_mc that's a movieClip. Ususally people use mc when they convert to a symbol.
either mc = MovieClip
gr = Graphic
bt = button
it just helps you understand what they are doing.
What your doing here
Code:
Mp3.onRelease=function(){
gotoAndStop(7);
loader_mc3.loadMovie("mp3Player_part2.swf")
with (loader_mc3){
_xscale=70
_yscale=70
}
}
First off Mp3. is a button
loader_mc3. is where your loadMovie into. So what you can do is replace the swf that you loaded.
So on another button load something into it
Code:
loader_mc3.loadMovie("someOther.swf");
or
Code:
loader_mc3.unloadMovie(1);
1 because it's in _level1
Hope that Helps
-
Thanks so much for trying to help, bmcc81. I tried the suggested method and it still isn't working. I suspect, though I could be wrong, that the problem lies with the Mp3 player action script calling for the creation of an empty movie clip (sound_mc). I think this means that even if the information loaded through loader_mc3 is replaced(in this case, a new swf file replaces the mp3 player), the sound_mc movie clip is separate, so the music doesn't stop. Is there a way to target sound_mc rather than the level?
-
Bmcc*81
You could try using
Put that in your button
Code:
Mp3.onRelease=function(){
gotoAndStop(7);
loader_mc3.loadMovie("mp3Player_part2.swf")
with (loader_mc3){
_xscale=70
_yscale=70
stopAllSounds();
}
}
That should stop all the sounds
-
Thank you! I used stopAllSounds and it works perfectly now.
-
Bmcc*81
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|