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

Sound problem code

New Here ,
Feb 09, 2013 Feb 09, 2013

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;

}

}

TOPICS
ActionScript
400
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

LEGEND , Feb 10, 2013 Feb 10, 2013

Try changing the following lines as indicated....

var isPlaying:Boolean = false;

...

channel = snd.play(pausePosition);  // remove these two lines

playBtn.gotoAndStop(2);

Translate
LEGEND ,
Feb 10, 2013 Feb 10, 2013
LATEST

Try changing the following lines as indicated....

var isPlaying:Boolean = false;

...

channel = snd.play(pausePosition);  // remove these two lines

playBtn.gotoAndStop(2);

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