Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-09-2010, 03:26 PM   #1
undefinedman
Registered User
 
Join Date: Mar 2009
Posts: 13
Default Play sound in first class, and stop in the other one.

Hi there!

I am trying to make some sound script for my website, but I need to stop the sound when portfolio's class will open.

Please help me, here is the URL:
www.pinysa.pl/www/_temp/Sound1.0.rar
undefinedman is offline   Reply With Quote
Old 04-10-2010, 08:15 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,824
Send a message via Skype™ to henke37
Default

So, what exactly do you need help with?
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 04-10-2010, 08:22 PM   #3
Artwich
Senior Member
 
Join Date: Mar 2010
Location: Rheinland-Pfalz, Germany
Posts: 245
Default

In the ContentPortfolio class, in the constructor, add:
ActionScript Code:
playSound();
__________________
Everything not logically conclusively proven impossible is possible.

Question all, for problems often lie where you least expect them.
Artwich is offline   Reply With Quote
Old 04-11-2010, 12:25 AM   #4
webwizaus
Registered User
 
Join Date: Apr 2010
Posts: 5
Default

This is very much like a problem that I was just about to post. I have music player when the swf starts and loops continuously or until "music off" button is activated. I would like the music to stop when a certain page is called or if that can't be done then when any button of the main menu is selected. If anyone can help me with this too I would be very grateful.
webwizaus is offline   Reply With Quote
Old 04-13-2010, 05:09 AM   #5
undefinedman
Registered User
 
Join Date: Mar 2009
Posts: 13
Default

The point is: How to stop the music in the other class.

Currently I have the three classes named: MainSound, Main, ContentPortfolio.

MainSound.as contains
Code:
package source.actionscript {
	trace("Opening MainSound.as");
	import flash.display.*;
	import flash.text.*;
	import flash.events.*;
	import flash.media.*;
	import flash.net.*;
	
	public class MainSound extends MovieClip {
		public var _Sound:Sound;
		public var _SoundChannel:SoundChannel;
		public var isPlaying:Boolean;
		
		public function MainSound() {			

		}
	}
}
The Main starts music

Code:
		public function playSound():void {
			if(!_MainSound.isPlaying) {
				trace("... Play sound ...");	
				with(_MainSound) {
					_SoundChannel = _Sound.play();
					isPlaying = true;
					_SoundChannel.addEventListener(Event.SOUND_COMPLETE, _SoundChannel_SOUND_COMPLETE);						
				}
			} else
			if(_MainSound.isPlaying) {
				trace("... Stop sound ...");
				with(_MainSound) {
					_SoundChannel.stop();
					isPlaying = false;
				}
			}			
		}
And finally ContentPortfolio class where I need to stop the music, but when I add the MainSound class to portfolio class to stop the music, I creating new sound channel so thats make two different channels, so I cant stop first one from that class of portfolio.

What should I do?
undefinedman is offline   Reply With Quote
Old 07-26-2010, 10:34 AM   #6
Szymciosek
Registered User
 
Join Date: Jul 2010
Posts: 2
Default

I've got the same problem like the friend above.. I have the classes where the first class is a constructor "MainSound.as", which is added to "Main.as" class. From main class I need to play music but in the third class "Movies.as" I need to stop the sound which is created in first class "MainSound". I tried just everything and I really don't know how to do it..
Szymciosek is offline   Reply With Quote
Old 07-26-2010, 04:55 PM   #7
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,824
Send a message via Skype™ to henke37
Default

It is as simple as getting the SoundChannel instance refference and calling the stop method on it.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 07-26-2010, 08:50 PM   #8
Szymciosek
Registered User
 
Join Date: Jul 2010
Posts: 2
Default

Hi again, maybe i am stupid or I don't understand.. I tried to do, but I still got errors... Can anyone help me write the classes?
Szymciosek is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.