Copy link to clipboard
Copied
Hi. Everytime I open my swf file, the sound is playing. How can I get the sound to not play from the very start of the swf file?Here's the code I got from google. Thanks in advance! This is action script 3.0 by the way.
import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.Event;
import flash.events.MouseEvent;
stop();
var req:URLRequest = new URLRequest("bgmusic.mp3");
var isPlaying:Boolean = true;
var snd:Sound = new Sound(req);
var channel:SoundChannel;
var pausePosition:Number = 0;
channel = snd.play(pausePosition);
playBtn.gotoAndStop(2);
playBtn.addEventListener(MouseEvent.CLICK, playPause);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event) {
pausePosition = 0;
channel = snd.play(pausePosition);
isPlaying = true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
function playPause(event:MouseEvent):void {
if (isPlaying == false) {
channel = snd.play(pausePosition);
isPlaying = true;
playBtn.gotoAndStop(2);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
else {
pausePosition = channel.position;
channel.stop();
playBtn.gotoAndStop(1);
isPlaying = false;
}
}
Try changing the following lines as indicated....
var isPlaying:Boolean = false;
...
channel = snd.play(pausePosition); // remove these two lines
playBtn.gotoAndStop(2);
Copy link to clipboard
Copied
Try changing the following lines as indicated....
var isPlaying:Boolean = false;
...
channel = snd.play(pausePosition); // remove these two lines
playBtn.gotoAndStop(2);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now