Skip to main content
Participating Frequently
December 9, 2018
Answered

Flash CS6 - how to repeat MovieClip sound only as long as MovieClip is on screen?

  • December 9, 2018
  • 1 reply
  • 521 views

I have a MovieClip with a sound inside of it. (This MovieClip is within other MovieClips and Graphics a few "layers" deep) It keeps playing the sound even after the MovieClip has finished on the timeline. Is it really best to avoid putting sounds inside MovieClips? I tried using AS3 to play the sound and stop it from a main MovieClip on the main timeline, but that didn't seem to work. The sound stopped for a single frame then kept playing, it seemed.

inside MovieClip:

var mySound:Sound = new MonsterFootstep();

var myChannel:SoundChannel = new SoundChannel();

myChannel = mySound.play();

inside main MovieClip on stage about 50 frames in:

monsterGirl.monsterGirlUpDown.monsterGirlLegsWalking.myChannel.stop();

Any help would be appreciated, thanks.

This topic has been closed for replies.
Correct answer kglad

(Basically I have a footstep sound that I want to repeat until the walking MovieClip that has the sound inside is done/off the timeline)


because you didn't answer the question i'll assume you're repeatedly executing the code you showed by repeatedly playing the frame that contains that code.  in that case, in the movieclip, use:

this.addEventListener(Event.ENTER_FRAME,f)

function f(e:Event):void{

myChannel.stop();

this.stop();

}

p.s. this probably isn't the best way to do this.

p.p.s. after seeing your message addendum, if your channel references are correct and you are repeatedly executing your sound play() code by repeatedly playing the frame(s) that contain that code, stop the timeline, too.

1 reply

kglad
Community Expert
Community Expert
December 9, 2018

you can use:

TyTBone

inside MovieClip:

var alreadyPlayed:Boolean;

if(!alreadyPlayed){

alreadyPlayed=true;

var mySound:Sound = new MonsterFootstep();

var myChannel:SoundChannel = new SoundChannel();

myChannel = mySound.play();

}

or, if you want to control the sound from outside that movieclip, you'll need a correct reference to myChannel.  you can use the trace function to find that reference.

TyTBoneAuthor
Participating Frequently
December 9, 2018

Thanks for responding. With your example, wouldn't the sound only play once? I'd like it to play until the MovieClip the sound is in stops existing on an internal timeline. Could I control the bool outside the internal timeline? Like "mc1.mc2.mc3.alreadyPlayed = true"?

Also, can you elaborate on how I could use the trace function to get the correct reference to myChannel? Why would the reference change? Is the scope of a SoundChannel basically "public"; could I do "myChannel.stop()" on the main timeline? (I haven't used AS3 in a while, I've been practicing with C#)

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 9, 2018

(Basically I have a footstep sound that I want to repeat until the walking MovieClip that has the sound inside is done/off the timeline)


because you didn't answer the question i'll assume you're repeatedly executing the code you showed by repeatedly playing the frame that contains that code.  in that case, in the movieclip, use:

this.addEventListener(Event.ENTER_FRAME,f)

function f(e:Event):void{

myChannel.stop();

this.stop();

}

p.s. this probably isn't the best way to do this.

p.p.s. after seeing your message addendum, if your channel references are correct and you are repeatedly executing your sound play() code by repeatedly playing the frame(s) that contain that code, stop the timeline, too.