Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
you can use:
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.
Copy link to clipboard
Copied
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#)
Copy link to clipboard
Copied
how do you make your sound repeat?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
(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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
"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();
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now