How to completely remove a movieclip in AS3

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.

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

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

Stop the timeline.

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