Stopping playback or sound with Actionscript

I have a map with 3 buttons. Each button you click displays a movieclip of a bubble with text and an embedded flv. When you click on the button again, the bubble goes away. My problem is if I click on the bubble to make it go away while the flv is playing (if I haven't paused it) the sound keeps playing because the movie keeps playing in the background (although hidden). I tried StopAllSounds, which worked but then caused problems with the flv playback. I don't care if the movie stops or pauses, or if we can just get the sound to go away until someone clicks back on the button. I'm hoping there's a simple bit of code I can add to the "else" statements in my code below. Any help would be appreciated!

Thanks!
coachella._visible = false;
holtville._visible = false;
calexico._visible = false;
 
coachella_btn.onPress = function() {
	if (coachella._visible == false) {
		coachella._visible = true;
	} else {
		coachella._visible = false;
	}
};
 
holtville_btn.onPress = function() {
	if (holtville._visible == false) {
		holtville._visible = true;
	} else {
		holtville._visible = false;
	}
};
 
calexico_btn.onPress = function() {
	if (calexico._visible == false) {
		calexico._visible = true;
	} else {
		calexico._visible = false;
	}
};

Open in new window

LVL 6
kmead6Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crooksy88Commented:
Firstly, if you have placed your flv playback components on the stage, set them to autoplay = false.

Then your code should look something like this:


PS. You can change pause(); to stop(); if you want the flv to play from the start every time.
coachella._visible = false;
 
coachella_btn.onPress = function() {
        if (coachella._visible == false) {
			
                coachella._visible = true;
		coachella.play();
        } else {
                coachella._visible = false;
		coachella.pause();
        }
};

Open in new window

0
kmead6Author Commented:
That seems like it should work but it doesn't. Do you think it's because I have the FLV grouped in a movie clip with text? Does it need to be by itself?
0
crooksy88Commented:
No but the path to the flv playback component will be different.

e.g. _root.movieclip_name.coachella._visible=false;
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

kmead6Author Commented:
I'm a little confused (sorry I'm a newbie). Here is my code now:

coachella._visible = false;

coachella_btn.onPress = function() {
      if (coachella._visible == false) {
            coachella._visible = true;
            _root.movieclip_name.coachella._visible=true;
            _root.movieclip_name.coachella.play();
      } else {
            coachella._visible = false;
            _root.movieclip_name.coachella._visible=false;
            _root.movieclip_name.coachella.stop();
      }
};

not sure if i used what you suggested correctly. basically i have a button called "coachella_btn" and when you click on it, up pops a movieclip called "coachella" that contains text and my FLV component. My FLV component is called "coachellaPlayer". The autoplay is set to false. I want the user to be able to click on the play button of the FLV component inside the mc and watch the video and then if they re-click on the "coachella_btn" before the video ends (without pressing pause first) it closes the "coachella" movieclip which in turn stops the "coachellaPlayer". confused? i am  =)
0
crooksy88Commented:
Sorry, I used 'movieclip_name' as a placeholder, sort of like 'type name here' would be used on a form.

Anyway, try this. What is happening here is you are specifying a path to the flv player. Dots are used in the same way that / would be used in a URL.

 _root.coachella.coachellaPlayer.play();
So this path starts off at the _root level (the main timeline), then looks inside the movieclip called coachella, then looks for the movieclip (or in this case a component) called coachellaPlayer and gives it the instruction play();

coachella._visible = false;

coachella_btn.onPress = function() {
      if (coachella._visible == false) {
            coachella._visible = true;
            _root.coachella._visible=true;
            _root.coachella.coachellaPlayer.play();
      } else {
            coachella._visible = false;
            _root.coachella.coachella._visible=false;
            _root.coachella.coachellaPlayer.stop();
      }
};
0
kmead6Author Commented:
OK. Thanks that actually makes some sense. Just tried it though and got this message "1000: Unable to make connection to server or to find FLV on server." I have the FLVs on my server and it always worked before, but now all the bubbles are visible at the beginning (no good) and there is no video. I've been hitting my head against a wall with this all day so please forgive if I sound frazzled.
0
crooksy88Commented:
This actionscript won't be the cause of that error message. The error relates to the flv component not being able to find the flv file.

Check that the path to the flv has not been changed.
0
kmead6Author Commented:
OK but what about everything being visible initially? I'm not sure why that happened with the new script but now all three bubbles are visible from the get go, each on top of each other.
0
crooksy88Commented:
Can you zip your flv and upload it somewhere so I can take a look?

0
kmead6Author Commented:
I tried uploading the file directly here but it stalled so I uploaded it to mediafire. Should work - let me know if you need anything else. Thank you so much!

http://www.mediafire.com/?wgmmiln25qj
0
crooksy88Commented:
OK, Let's try this and see if it gives you the results you want.

Remove or comment out the first 3 lines of code. (Adding // before a line of code will comment it out and disable it)

//_root.coachella.coachellaPlayer.play();
//_root.holtville.holtvillePlayer.play();
//_root.calexico.calexicoPlayer.play();

Test the movie.
0
crooksy88Commented:
I've also noticed a few things that are incorrect with your code...

coachella._visible = true;
 _root.coachella._visible=true;

in this instance these two line of code do exactly the same thing.


 _root.coachella.coachella._visible=false;

Here you are looking for a movieclip called coachella inside a movieclip called coachella. That does not exist.

At the moment it is possible to click on one movie to start it, then click on another and this will start as well so you have two movies running at the same time. What needs to happen is that when you click a button it starts that movie but stops the other two. You can tell a movie to stop even if it isn't running. Flash doesn't mind that.

Replace all of your code on frame 1 with the following and see what you think.
coachella._visible = false;
holtville._visible = false;
calexico._visible = false;
 
coachella_btn.onPress = function() {
      if (coachella._visible == false) {
            coachellaPlay();
			hotvilleStop();
			calexicoStop();
      } else {
            coachella._visible = false;
            coachellaStop();
      }
};
 
holtville_btn.onPress = function() {
      if (holtville._visible == false) {
        	coachellaStop();
			hotvillePlay();
			calexicoStop();
      } else {
            hotvilleStop();
      }
};
 
calexico_btn.onPress = function() {
      if (calexico._visible == false) {
            coachellaStop();
			hotvilleStop();
			calexicoPlay();
      } else {
            calexicoStop();
      }
};
 
 
function coachellaPlay() {
_root.coachella._visible=true;
_root.coachella.coachellaPlayer.play();	  
}
 
 
function coachellaStop() {
_root.coachella._visible=false;
_root.coachella.coachellaPlayer.stop();			  
}
 
 
function hotvillePlay() {
_root.holtville._visible=true;
_root.holtville.holtvillePlayer.play();	  
}
 
 
function hotvilleStop() {
_root.holtville._visible=false;
_root.holtville.holtvillePlayer.stop();			  
}
 
 
function calexicoPlay() {
_root.calexico._visible=true;
_root.calexico.calexicoPlayer.play();	  
}
 
 
function calexicoStop() {
_root.calexico._visible=false;
_root.calexico.calexicoPlayer.stop();			  
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kmead6Author Commented:
thanks for taking the time to look through that. i'll check it out as soon as i get home this afternoon.
0
kmead6Author Commented:
absolutely beautiful! thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.