Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now