Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stopping sound when frame is exited

Posted on 2009-05-12
11
Medium Priority
?
382 Views
Last Modified: 2013-11-12
Hi,
I have a problem. I dragged this movieclip to my stage which resides in a movieclip that is called tino the main timeline. The .mp3 player works fine but when I navigate away from the page the sound is still playing. How do I turn this sound off when the frame is left by the user? I know I probably have to use the Sound.close(); but I have no clue how to implement this. I have tried many many ways to get this to work.

Thanks,
Tammy
// Create the Sound objects and URLRequest that will hold the audio files
var music:Sound = new Sound(new URLRequest ("audio/saveyourbreath.mp3"));
 
// Create the Sound Channel variable
var sc:SoundChannel;
 
// Variable to stop initial playing of song when user loads page
var isPlaying:Boolean = false;
 
// Create function for Stop button
function stopMusic(e:Event):void {
	sc.stop();
	isPlaying = false;
}
 
// Create function for Play Button
function playMusic(e:Event):void
{
	if (!isPlaying)
	{
		sc = music.play();
		isPlaying = true;
	}
}
 
// assign button functions to the buttons Play & stop buttons
playbtn.addEventListener(MouseEvent.CLICK, playMusic);
stopbtn.addEventListener(MouseEvent.CLICK, stopMusic);
 
// Volume Slider
// Set Dragging variable of slider to False
var dragging:Boolean = false;
 
// x and y coordinates of slider and 
// the width of the line to be ale to slide along and the height set to 0
var rectangle:Rectangle = new Rectangle(0,0,100,0);
 
// Add event listener to volume slider buttons
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
 
// Set functions of the slider
function dragIt(e:Event):void {
	volume_mc.slider_mc.startDrag(false,rectangle);
	dragging = true;
	
	// event listener to adjust volume
	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function dropIt(e:Event):void {
	if(dragging)
	{
		volume_mc.slider_mc.stopDrag();
		dragging = false;
	}
}
 
// function to adjust the volume of the audio clip
function adjustVolume(e:Event):void {
	// find coordinates of volume_mc and divide by 100 to adjust volume
	var vol:Number = volume_mc.slider_mc.x/100;
	var st:SoundTransform = new SoundTransform(vol);
	if (sc != null)
	{
		sc.soundTransform = st;
	}
}

Open in new window

0
Comment
Question by:ladyrider12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 11

Expert Comment

by:Eaddy Barnes
ID: 24370478
hello.

could you tell me how the user leaves the frame in question.

1  does he have to press a button to leave the frame.
2  is the user made to leave after a loading process is completed


GE
0
 

Author Comment

by:ladyrider12
ID: 24370507
The user leaves the frame by clicking navigation buttons whichare also movie clips.
0
 
LVL 11

Expert Comment

by:Eaddy Barnes
ID: 24370620
did you try attaching the stop sound script to the onClick function of the button?

GE
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:ladyrider12
ID: 24370641
I'm sorry. I am learning actionscript and I am not sure what you mean. I have tried numerous things. What would you do with the code snippet I gave in the thread? Wouldn't that stop the sound when you click the on button or am I understanding you wrong?
0
 
LVL 11

Expert Comment

by:Eaddy Barnes
ID: 24370777
what i mean is..

which one is the script belong to the button you would use to navigate away from the frame

GE
0
 

Author Comment

by:ladyrider12
ID: 24370875
Actually there are numerous buttons that are in movieclips themselves. If you send me your email address I can send you the file. It is not uploading to here even though I have .zip it.
0
 

Author Comment

by:ladyrider12
ID: 24371195
Uploaded my file to one of my websites.

http://www.discounthorsetack.net/TamaraThoel_final2.fla
0
 
LVL 11

Assisted Solution

by:Eaddy Barnes
Eaddy Barnes earned 200 total points
ID: 24371198
speraspearpro@yahoo.com
0
 

Author Comment

by:ladyrider12
ID: 24375303
I figured it out. I put a stop(); at the beginning of each page or frame and this got the sound to stop.
Thanks for you help.
0
 

Accepted Solution

by:
ladyrider12 earned 0 total points
ID: 24375313
My instrustor may not be happy with this simple work around but I really don't care after 2 days of working on it. LOL
0
 

Author Comment

by:ladyrider12
ID: 24375389
Even though I figured it out. This moderator was very patient and tried to help me.
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question