views:

547

answers:

2

I am trying to stop the audio of the video swf and i can't get it to stop. Here is my code for loading the file

var myLoader:Loader= new Loader(); myLoader.x=420; myLoader.y=200; // boolean variable set for use below in our function var screenCheck:Boolean = false; //These three linces keep stafe elements the same size, so they don't distort var swfStage:Stage = this.stage;

video_btn.addEventListener(MouseEvent.CLICK,contentvideo);

function contentvideo (event:MouseEvent):void{ myLoader.load(new URLRequest("prevideo.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

Now i have other functions that load different URLRequest and when the are loading the audio keeps playing do i have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing

A: 

Im not familair with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that

addChild(myLoader);

has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?

A shot in the dark I know but I thought Id offer the possibility anyway.

intermension
A: 

The code i was given was from my flash web class here is the entire code i use.

//this is my video.swf file. this has all of the video files that i brought in.

stop();

function videoOne(event:MouseEvent): void{

pubPlayer.source=("mys.flv");
}

function videoTwo(event:MouseEvent):void{

pubPlayer.source=("arm.flv");
}

function videoThree(event:MouseEvent): void{

pubPlayer.source=("one.flv");
}

function videoFour(event:MouseEvent):void{

pubPlayer.source=("if.flv");
}

function videoFive(event:MouseEvent): void{

pubPlayer.source=("higher.flv");
}

function videoSix(event:MouseEvent):void{

pubPlayer.source=("video.flv");
}

my_btn.addEventListener(MouseEvent.CLICK, videoOne);

arm_btn.addEventListener(MouseEvent.CLICK, videoTwo);

one_btn.addEventListener(MouseEvent.CLICK, videoThree);

if_btn.addEventListener(MouseEvent.CLICK, videoFour);

higher_btn.addEventListener(MouseEvent.CLICK, videoFive);

bul_btn.addEventListener(MouseEvent.CLICK, videoSix);

//then this is where i am loading in all of my external swf files into a functional webpage

volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest; var music:Sound = new Sound(); var sc:SoundChannel; var currentSound:Sound = music; var pos:Number; var songPlaying:Boolean = false;

var xml:XML; var songlist:XMLList; var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void { xml = new XML(e.target.data); songlist = xml.song; musicReq = new URLRequest(songlist[0].url); music.load(musicReq); sc = music.play(); title_txt.text = songlist[0].title; artist_txt.text = songlist[0].artist; sc.addEventListener(Event.SOUND_COMPLETE, nextSong); }

loader.load(new URLRequest("music.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong); prev_btn.addEventListener(MouseEvent.CLICK, prevSong); pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);

stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void { if (currentIndex < (songlist.length() - 1)) { currentIndex++; } else { currentIndex = 0; }

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);

}

function prevSong(e:Event):void { if (currentIndex > 0) { currentIndex--; } else { currentIndex = songlist.length() - 1; }

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);

}

function pauseSong(e:Event):void { pos = sc.position; sc.stop(); songPlaying = false; play_btn.addEventListener(MouseEvent.CLICK,playSong); }

function playSong(e:Event):void { if(songPlaying == false) { sc = currentSound.play(pos); sc.addEventListener(Event.SOUND_COMPLETE, nextSong); songPlaying = true; play_btn.removeEventListener(MouseEvent.CLICK,playSong); } }

function stopSong(e:Event):void { sc.stop(); pos = 0; songPlaying = false; play_btn.addEventListener(MouseEvent.CLICK,playSong); }

//----VOLUME----// var dragging:Boolean = false; var rect:Rectangle = new Rectangle(0,0,28,0); volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt); volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt); stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void { dragging = true; e.target.startDrag(false,rect); e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume); }

function dropIt(e:Event):void { if (dragging) { var vol:Number = volume_mc.slider_mc.x * .02; var st:SoundTransform = new SoundTransform(vol,0); sc.soundTransform = st; volume_mc.slider_mc.stopDrag(); volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume); dragging = false; } }

function adjustVolume(e:Event):void { var vol:Number = volume_mc.slider_mc.x * .02; var st:SoundTransform = new SoundTransform(vol,0); sc.soundTransform = st; }

var myLoader:Loader= new Loader(); var myVideo:Loader= new Loader(); myLoader.x=420; myLoader.y=200; // boolean variable set for use below in our function var screenCheck:Boolean = false; //These three linces keep stafe elements the same size, so they don't distort var swfStage:Stage = this.stage;

disc_btn.addEventListener(MouseEvent.CLICK,contentdisc);

function contentdisc (event:MouseEvent):void{ myLoader.load(new URLRequest("prelmusic.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

home_btn.addEventListener(MouseEvent.CLICK,contenthome);

function contenthome (event:MouseEvent):void{ myLoader.load(new URLRequest("prehome.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

video_btn.addEventListener(MouseEvent.CLICK,contentvideo);

function contentvideo (event:MouseEvent):void{ myLoader.load(new URLRequest("prevideo.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

links_btn.addEventListener(MouseEvent.CLICK,contentlinks);

function contentlinks (event:MouseEvent):void{ myLoader.load(new URLRequest("prelinks.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

history_btn.addEventListener(MouseEvent.CLICK,contenthistory);

function contenthistory (event:MouseEvent):void{ myLoader.load(new URLRequest("prehistory.swf")); addChild(myLoader); movie_btn.stop(); movie_btn.visible=false; }

about_btn.addEventListener(MouseEvent.CLICK,contentabout);

function contentabout (event:MouseEvent):void{ myLoader.load(new URLRequest("preabout.swf")); addChild(myLoader); movie_btn.stop() movie_btn.visible=false; }

Again Im not really familar with what you'e doing but it looks like sc is a soundChannel. Does setting sc=null before setting sc =nextTitle.play in your whenLoaded, nextSong and prevSong events do anything? Alternatively can you kill the current track via the sc variable before setting sc equal to something else? i.e. sc.Stop(); then sc=nextTitle.play();
intermension