Solved

Stopping playback or sound with Actionscript

Posted on 2009-07-12
14
806 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
Comment Utility
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
Comment Utility
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
Comment Utility
No but the path to the flv playback component will be different.

e.g. _root.movieclip_name.coachella._visible=false;
0
 
LVL 6

Author Comment

by:kmead6
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 6

Author Comment

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

0
 
LVL 6

Author Comment

by:kmead6
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
absolutely beautiful! thank you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now