Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Play/stop sound on one button (AS3)

New Here ,
Jan 27, 2011 Jan 27, 2011

hello

when you click the first time on the button, it should start the song, when you click a second time on the button, it should stop the song. how do i make this with actionscript 3?

regards

simon

TOPICS
ActionScript
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 27, 2011 Jan 27, 2011

A very basic example:

You'd need 3 var:

private var _sound:Sound;
private var _soundChannel:SoundChannel;
private var _soundChannelPosition:Number = 0;

Then create a Sound:

_sound = new Sound(new URLRequest("some.mp3"));

Stop/play the sound on click:

        private function click(e:MouseEvent):void {
            if(_soundChannel == null){
                _soundChannel = _sound.play(_soundChannelPosition);
            } else {
                _soundChannelPosition = _soundChannel.position;
                _s
...
Translate
Community Expert ,
Jan 27, 2011 Jan 27, 2011
LATEST

A very basic example:

You'd need 3 var:

private var _sound:Sound;
private var _soundChannel:SoundChannel;
private var _soundChannelPosition:Number = 0;

Then create a Sound:

_sound = new Sound(new URLRequest("some.mp3"));

Stop/play the sound on click:

        private function click(e:MouseEvent):void {
            if(_soundChannel == null){
                _soundChannel = _sound.play(_soundChannelPosition);
            } else {
                _soundChannelPosition = _soundChannel.position;
                _soundChannel.stop();
                _soundChannel = null;
            }
        }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines