Link to home
Start Free TrialLog in
Avatar of kmead6
kmead6Flag for United States of America

asked on

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

Avatar of crooksy88
crooksy88
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of kmead6

ASKER

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?
No but the path to the flv playback component will be different.

e.g. _root.movieclip_name.coachella._visible=false;
Avatar of kmead6

ASKER

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  =)
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();
      }
};
Avatar of kmead6

ASKER

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.
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.
Avatar of kmead6

ASKER

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.
Can you zip your flv and upload it somewhere so I can take a look?

Avatar of kmead6

ASKER

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
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.
ASKER CERTIFIED SOLUTION
Avatar of crooksy88
crooksy88
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kmead6

ASKER

thanks for taking the time to look through that. i'll check it out as soon as i get home this afternoon.
Avatar of kmead6

ASKER

absolutely beautiful! thank you!