How to make a MovieClip remove itself in AS3?

后端 未结 5 1450
不思量自难忘°
不思量自难忘° 2021-01-18 13:41

What is the equivalent to removeMovieClip() in AS3?

Apparently many have the same question:
StackOverflow:

  1. How to completely remove a
相关标签:
5条回答
  • 2021-01-18 14:16
    public static function removeDisplayObject(displayObject:DisplayObject):void {
        /* normal code
        if(displayObject && displayObject.parent){
            displayObject.parent.removeChild(displayObject);
        }
         */
        displayObject ? displayObject.parent ? displayObject.parent.removeChild(displayObject) : null : null;
    }
    
    0 讨论(0)
  • 2021-01-18 14:21
    this.parent.removeChild(this);
    

    This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:

    import flash.display.*
    

    You should also remove the event listener on it before removing it.

    0 讨论(0)
  • 2021-01-18 14:30

    Always ensure that those self removing movieclips can get garbage collected. This solution wiped away all my instances from a loaded swf's library symbol:

    var mc:MovieClip = new definition() as MovieClip;
    addChild(mc);
    
    mc.x = 1000 * Math.random();
    mc.y = 1000 * Math.random();
    
    mc.addFrameScript(mc.totalFrames - 1, function onLastFrame():void
    {
        mc.stop();
        mc.parent.removeChild(mc);
        mc = null;
    });
    
    0 讨论(0)
  • 2021-01-18 14:30

    I use, in an extra blank keyframe at the end of the MovieClip which should remove itself:

    stop();
    MovieClip(parent).removeChild(this);
    

    Found it to be the proper and best solution.

    0 讨论(0)
  • 2021-01-18 14:33

    If your animation is ending on frame 20.

    note: using 19 because flash count frames from zero(0) similar to array index.

    class animatedCloud
    {
    
        public function animatedCloud(){
            addFrameScript(19, frame20);
        }
    
        private function frame20(){
            parent.removeChild(this);
        }
    }
    
    0 讨论(0)
提交回复
热议问题