How to completely remove a movieclip in AS3


#1

I have a MovieClip(mc) on stage. this Mc has sound in its timeline. I use removeChild(mc); to remove Movie clip from stage. but the sound can’t stop.


#2

Welcome to the Envato community!

You need to stop the audio prior to removing the mc movieclip from stage.

import flash.media.SoundMixer;
import flash.events.MouseEvent;

//assuming you remove the mc movieclip on button click
someButton.addEventListener(MouseEvent.CLICK, removeTheMcMovieclip);

function removeTheMcMovieclip(e:MouseEvent):void
{
	SoundMixer.stopAll();//calling the stopAll() method of the SoundMixer Class will stop the sound
	this.removeChild(mc);//we can now safely remove the movieclip
	this.mc = null;//clean up the memory
}

read more about the subject here and here.

Hope this helps!

Cheers,
Dani


#3

Hi Dani,

Thanks for your response,

My code is given below. I have a movieClip(mc) in library. and I addChild it on stage. this movieclip contain sounds in its timeline.

import flash.events.Event;
import flash.events.MouseEvent;
var objMc:mc = new mc();
addChild(objMc);
SoundMixer.stopAll();
removeChild(objMc);
objMc = null;

but the sound is still playing

Thanks & Regards
Ashwini


#4

Stop the timeline.


#5

If the sound in the MovieClip is streaming type , just stop the timeline :wink: