Copy link to clipboard
Copied
Hello everyone. I was hoping someone could share some AS3 knowledge with me
Situation - I have multiple frames. Each frame contains a movieclip. Each movie clip has audio and a seeker bar. There is a back and next button to go between the frames on the main timeline.
Issue - When pressing back or next button, movieclip audio does not stop and it overlaps to the next or previous frame!
Desired outcome - When clicking the next or back button, it will stop 'any' movieclip that is playing prior to moving to next or previous frame.
I suspect I will be having a lot of frames (therefore a lot of movie clips), so individually coding each back/next button per frame for one specific movieclip is a bit of a hassle and proving to be buggy at this stage.
Question - Is there, and if there is, what is the function to make all movieclips stop playing?
e.g
function next(Event:MouseEvent):void{
<stop(); all movie clips>
nextFrame();
}
next_btn.addEventlistener(MouseEvent.CLICK, next);
Thanks everyone! Your insight is most welcomed and will be appreciated.
you could use:
function stopAllF(mc:*):void{
mc.stop();
if(mc is MovieClip){
for(var i:int=0;i<mc.numChildren;i++){
if(mc.getChildAt(i) is MovieClip){
stopAllF(MovieClip(mc.getChildAt(i)));
}
}
}
}
but i would recommend using removedfromstage code for the flvplayback components and leave stopAllF that way it was.
btw, if you have a small number of movieclips to stop on a frame and they have no child movieclips that need to be stopped, the same removedfromstage code will work for them too.
and aga
...Copy link to clipboard
Copied
i'm not sure you need to stop all movieclips, but it can be done by calling stopAllF and passing the parent movieclip.
function stopAllF(mc:MovieClip):void{
mc.stop();
for(var i:int=0;i<mc.numChildren;i++){
if(mc.getChildAt(i) is MovieClip){
stopAllF(MovieClip(mc.getChildAt(i)));
}
}
}
Copy link to clipboard
Copied
tthanks for replying!! If I don't need to stop all movie clips how can I stop the bugs from happening?
aalso, I need to make it into a button so how do i make the code you gave me in one
Copy link to clipboard
Copied
the best way to handle that issue is to use the Event.REMOVED_FROM_STAGE event to explicitly stop whatever processes (including sound) that should be stopped.
to have a button call the function i posted, use:
btn.addEventListener(MouseEvent.CLICK, btnF);
function btnF(e:MouseEvent):void{
stopAllF(this); // assuming 'this' is the timeline that is the parent of the movieclips you want to stop.
}
Copy link to clipboard
Copied
Thanks for that! It is much cleaner than what I have so far and is of great help.
Is it possible to not just include movieclips, but FLVplaybacks as well?
Also, I'm interested in how you would go about coding for the Event.REMOVED_FROM_STAGE feature. At this current stage, I am still having audio lapsing over to a frame, but it is specifically on the last two frames.
Copy link to clipboard
Copied
eg,
flv_pb.addEventListener(Event.REMOVED_FROM_STAGE,removedF);
function removedF(e:Event):void{
flv_pb.stop();
}
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
I FOUND OUT THE ISSUE!
I needed to add one blank keyframe infront of the Audio, before the audio commences.
This has solved the audio issue, HOWEVER.
The codes you have given me are amazing and I have learnt so much from it. I am also using them as they are a lot cleaner than what I currently have. Thank you.
Just one last thing, my code is currently -
next_btn.addEventListener(MouseEvent.CLICK, next);
function stopAllF(mc:MovieClip):void{
mc.stop();
for(var i:int=0;i<mc.numChildren;i++){
if(mc.getChildAt(i) is MovieClip){
stopAllF(MovieClip(mc.getChildAt(i)));
}
}
}
function next(event:MouseEvent):void{
stopAllF(this);
nextFrame();
}
I see that you referred mc to a MovieClip(is this right?)
And this function and command will complete itself for all movie clips.
Some of my future frames I'll be having FLV Playback videos, how do I 'include any' FLVplayback videos into this code?
Copy link to clipboard
Copied
you could use:
function stopAllF(mc:*):void{
mc.stop();
if(mc is MovieClip){
for(var i:int=0;i<mc.numChildren;i++){
if(mc.getChildAt(i) is MovieClip){
stopAllF(MovieClip(mc.getChildAt(i)));
}
}
}
}
but i would recommend using removedfromstage code for the flvplayback components and leave stopAllF that way it was.
btw, if you have a small number of movieclips to stop on a frame and they have no child movieclips that need to be stopped, the same removedfromstage code will work for them too.
and again, please mark helpful/correct responses.
Copy link to clipboard
Copied
Thank you, that is helpful. I am understanding what that code means now.
I can't use the removedfromstage code because I don't understand how it works?
The code sample you gave me
flv_pb.addEventListener(Event.REMOVED_FROM_STAGE,removedF);
function removedF(e:Event):void{
flv_pb.stop();
}
is only removing an instance called "flv_pb"
I don't know how to make it to remove any flvpb and any movieclip.
Copy link to clipboard
Copied
instead of flv_pb, use the name of any movieclip or flvplayback component whose play you want to stop when it's removed from the stage (ie, you change keyframes from one where the object exists to another where it no longer exists.)
Copy link to clipboard
Copied
Thanks, but I know that already. That's not the issue with using that code. The issue is that I don't want to have to type in every instance names, on each frame.
I have a button that runs across the main timeline and it's function is, as you gave me above, to stop 'any' movieclips.
Anyways. It seems, for the most part this issue has been resolved. Thanks for your help. If you do happen to know how to make the removedfromstage code work for 'any' instances, instead of one specific one that'll be lovely.
Copy link to clipboard
Copied
in the frame with your button listener add the following two functions. when your button is clicked, before executing the goto, call stopWhenRemovedF(this);
function stopWhenRemovedF(mc:MovieClip):void{
for(var i:int=0;i<numChildren;i++){
if(mc.getChildAt(i) is MovieClip || mc.getChildAt(i) is FlvPlayback){
mc.getChildAt(i).addEventListener(Event.REMOVED_FROM_STAGE,removedF);
}
}
}
function removedF(e:Event):void{
e.currentTarget.stop();
}
Copy link to clipboard
Copied
Thank you. It helped solved a lot of my issues. Cheers.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Ok I have cleaned up the codes and this is what I found
There are 4 frames currently,
Frame 1 - has FLV video playback and video components to control it.
Frames 2 - 4 - has a movieclip each as the main content. Instance names of the contents are as content1, content2, content3.
Each frames has a back and next button, using codes given from above. It seems to work, BUT -
Going from frame 4 "BACK" to frame 3, I can hear the audio of frame 2.
(aka)
Going from content3 "BACK" to content2, I can hear content1.
Experimented with - Deleting content1 from frame 2 - fixed the issue.
Experimented with - Adding content2/3 on frame 2 - same issue, but I'll hear whatever is on frame 2.
No idea why Frame 2 is loading itself onto frame 3, only when you come back from frame 4!!
Copy link to clipboard
Copied
what causes your sound to play in frame 2? code? sound attached to a timeline?
if sound is attached to a timeline, is its sync property 'stream'? (hint: if it's not, change it to stream and retest.)