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

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

New Here ,
Dec 09, 2018 Dec 09, 2018

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.

442
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

Community Expert , Dec 09, 2018 Dec 09, 2018

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 t

...
Translate
Community Expert ,
Dec 09, 2018 Dec 09, 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.

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
New Here ,
Dec 09, 2018 Dec 09, 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#)

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
Community Expert ,
Dec 09, 2018 Dec 09, 2018

how do you make your sound repeat?

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
New Here ,
Dec 09, 2018 Dec 09, 2018

timeline.png

Currently I have the AS3 inside the walking MovieClip. It's actually 2 sound channels for each footstep.

var mySound:Sound = new MonsterFootstep();

var myChannel:SoundChannel = new SoundChannel();

myChannel = mySound.play();

var mySound2:Sound = new MonsterFootstep();

var myChannel2:SoundChannel = new SoundChannel();

myChannel2 = mySound2.play();

Then on the main timeline I have these which are supposed to stop the sounds, I thought:

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

eleven.monsterGirl.monsterGirlUpDown.monsterGirlLegsWalking.myChannel2.stop();

But the sound continues.

---

I also tried to do

var donePlaying:Boolean = false;

if (!donePlaying){

     var mySound:Sound = new MonsterFootstep();

     var myChannel:SoundChannel = new SoundChannel();

     myChannel = mySound.play();

}

And have "eleven.monsterGirl.monsterGirlUpDown.monsterGirlLegsWalking.donePlaying = true;" on the main timeline when I want the sound to stop, but the sound continues. Is "var donePlaying:Boolean = false;" recreated each time the sound with the movieclip repeats?

To be honest, solving this isn't the biggest issue because I can just have multiple sounds on the main timeline, but I was curious about how to solve this.

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
New Here ,
Dec 09, 2018 Dec 09, 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)

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
Community Expert ,
Dec 09, 2018 Dec 09, 2018

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.

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
New Here ,
Dec 09, 2018 Dec 09, 2018

"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."

I think this solved it, thanks! I stopped the two channels but also the timeline.

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

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

monsterGirl.monsterGirlUpDown.monsterGirlLegsWalking.stop();

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
Community Expert ,
Dec 09, 2018 Dec 09, 2018
LATEST

you're welcome.

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