Solved

Stopping playback or sound with Actionscript

Posted on 2009-07-12
14
808 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:kmead6
  • 7
  • 7
14 Comments
 
LVL 13

Expert Comment

by:crooksy88
ID: 24837502
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
 
LVL 6

Author Comment

by:kmead6
ID: 24837583
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
 
LVL 13

Expert Comment

by:crooksy88
ID: 24837604
No but the path to the flv playback component will be different.

e.g. _root.movieclip_name.coachella._visible=false;
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 6

Author Comment

by:kmead6
ID: 24837655
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
 
LVL 13

Expert Comment

by:crooksy88
ID: 24837731
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
 
LVL 6

Author Comment

by:kmead6
ID: 24837796
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
 
LVL 13

Expert Comment

by:crooksy88
ID: 24837815
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
 
LVL 6

Author Comment

by:kmead6
ID: 24837826
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
 
LVL 13

Expert Comment

by:crooksy88
ID: 24837843
Can you zip your flv and upload it somewhere so I can take a look?

0
 
LVL 6

Author Comment

by:kmead6
ID: 24840788
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
 
LVL 13

Expert Comment

by:crooksy88
ID: 24841053
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
 
LVL 13

Accepted Solution

by:
crooksy88 earned 500 total points
ID: 24841234
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
 
LVL 6

Author Comment

by:kmead6
ID: 24841557
thanks for taking the time to look through that. i'll check it out as soon as i get home this afternoon.
0
 
LVL 6

Author Closing Comment

by:kmead6
ID: 31602704
absolutely beautiful! thank you!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

810 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