I have a MovieClip on the main timeline on frame 5. It's called "slideShow_mc". I also have the following code
function startSlideshow():void {
slideShow_mc.loadSlides(loadXml.xmlArray);
}
Inside slideShow_mc I call a custom class:
function loadSlides(xml_file:Array):void
{
var slides开发者_Python百科:SlideShow = new SlideShow(xml_file);
addChild(slides);
slides.x = 0;
slides.y = 0;
}
If I go to other frames slideShow_mc disappears but the trace statements in the SlideShow class tell me that it's still there. How do I remove it? trace(slideShow_mc.numChildren) returns 0. trace(numChildren) inside the loadSlides method returns 0 as well.
All you are doing by moving to another frame is removing the slider from the stage. If it contains internal listeners that are receiving events then you need to shut those down. You could try listening for the removedFromStage event inside slideShow_mc and then calling a destroy function on your slider.
//inside slideShow_mc:
//define slides in a wider scope so we can kill it later:
var slides:SlideShow;
//listen for this container being removed
this.addEventListener(Event.REMOVED_FROM_STAGE,onRemoved);
//load slide function
function loadSlides(xml_file:Array):void
{
slides = new SlideShow(xml_file);
addChild(slides);
slides.x = 0;
slides.y = 0;
}
//remove handler
function onRemoved(evt:Event):void
{
this.addEventListener(Event.REMOVED_FROM_STAGE,onRemoved);
if(slides != null) {
//call a function in the SlideShow class to kill its internal workings
slides.destroy();
//free up the object for gc
slides = null;
}
}
Obviously slides.destroy()
is conjecture on my part. There may be a function in your class that shuts down its behaviour, or you might have to create one, and it may not be named destroy.
精彩评论