A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] [CS3] mp3 player swf keeps playing when go to other pages

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    14

    resolved [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 
    0i<playlist.firstChild.childNodes.lengthi++) {
                
    _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(filenameband) {
        if (
    this.sound_obj) {
            
    this.sound_obj.stop();
            
    delete this.sound_obj;
        }
        
    this.sound_obj = new Sound(this);
        
    this.sound_obj.loadSound(filetrue);
        
    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(timer1000this.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=_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(thistrue0this._ythis._parent.volBG._widththis._y);
            
    this.onEnterFrame = function() {
                var 
    = (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=_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-_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

  2. #2
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299
    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.
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    14
    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.

  4. #4
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299
    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
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  5. #5
    Junior Member
    Join Date
    May 2008
    Posts
    14
    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?

  6. #6
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299
    You could try using
    Code:
    stopAllSounds();

    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
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

  7. #7
    Junior Member
    Join Date
    May 2008
    Posts
    14
    Thank you! I used stopAllSounds and it works perfectly now.

  8. #8
    Bmcc*81 bmcc81's Avatar
    Join Date
    Jul 2007
    Location
    Montreal
    Posts
    299
    Glade I could help.
    Bmcc81
    Flash Designer / Web Developer
    -----------------------------------
    http://www.webinkgraphics.com

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