سؤال

This code generates airport symbol as a part of a bigger presentation. That works pretty well, but at the moment the objects don't disappear when I change frame, which I would like them to.

I've tried different methods in the other frame, but whatever I do i get the error: "Call to a possibly undefined method removeChild through a reference with static type Class."

I'm pretty new to AS3, so keep that in mind :)

Thank you. Below is my code.

for (var key:Object in Airports) 
{
var MyAirport = new airport();
MyAirport.x = Airports[key]["x"];
MyAirport.y = Airports[key]["y"];
MyAirport.width = 17;
MyAirport.height = 17;
addChild(MyAirport)
MyAirport.addEventListener(MouseEvent.CLICK, this.clickHandler)
 }
هل كانت مفيدة؟

المحلول

Put all your movieclips for each scene into an array as you build each scene. Then you can loop through that array and remove them by calling a cleanup function:

function cleanupView():void
{
    for( var i:int = 0; i < collectedMovieClipsArray; i++ )
    {
        var parentContainer:MovieClip = collectedMovieClipsArray[ i ].parent as MovieClip;
        parentContainer.removeChild( collectedMovieClipsArray[ i ] );
    }
}

the as MovieClip part my not be necessary.

نصائح أخرى

Thanks for your answer. However I chose a simple path by using the following line:

this.parent.visible = false

This is hiding all the MovieClips I will try to implement your code, though.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top