Skip to main content
Known Participant
October 13, 2012
Question

How to stop sound from playing everytime we go to 1st frame ?*

  • October 13, 2012
  • 4 replies
  • 1765 views

Hi everyone, my app has 3 frames and a sound playing on background so everytime i go to 1st frame the music play's over himself,

is easy to get 5 instances of the music playing at same time.

How to stop this behavior ?

Music file imported to library.

Sound Linkage: export for actionScript

Sound Linkage: export in frame 1

Any help are welcome

Flash CS6 - AIR 3.4 Android and iOS > CODE:

//sound

var bgSound:BGLoop = new BGLoop();

var channel:SoundChannel=new SoundChannel();

playMusic();

//making mute;

soundBtn.addEventListener(MouseEvent.MOUSE_UP , mute);

function mute(event:MouseEvent) {

    //removing mute function then adding unmute function to same button

    soundBtn.removeEventListener(MouseEvent.MOUSE_UP , mute);

    soundBtn.addEventListener(MouseEvent.MOUSE_UP , unMute);

    //making symbol to visible;

    soundBtn.gotoAndStop(2);

    //set the volume false;

    SoundMixer.soundTransform = new SoundTransform(0);

}

//making unmute

function unMute(event:MouseEvent) {

    soundBtn.removeEventListener(MouseEvent.MOUSE_UP , unMute);

    soundBtn.addEventListener(MouseEvent.MOUSE_UP , mute);

    soundBtn.gotoAndStop(1);

    //set the volume true;

    SoundMixer.soundTransform = new SoundTransform(1);

}

function playMusic():void {

    channel = bgSound.play();

    channel.addEventListener(Event.SOUND_COMPLETE, loopMusic);

}

function loopMusic(e:Event):void {

    if (channel != null) {

        channel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);

        playMusic();

    }

}

This topic has been closed for replies.

4 replies

October 13, 2012

Add a frame to your movieclip, so you never go back to frame 1, but to frame 2.

HarpiolinAuthor
Known Participant
October 13, 2012

@djnr i got this:

Frame 1: Home Screen - Help Screen

Frame 2: GamePlay Screen

Frame 3: Score Screen

Ok, i'll block the return to Home Screen, so the player will need to restart the app to see Home again.

Many thank's.

Mark.fromOP
Inspiring
October 15, 2012

Another way to do this is to create a boolean right off the start. Lets say var createMusicTrack:Boolean and set it to true

Then load your music and start playing it and at the end of that load code add a line that sets the boolean to false so that when you come back to frame 1 the boolean will be false and the code will not load and play, but this could be problematic too. Djnr suggestion is better for your purposes.