Removechild unknown identifier

removechild is not working
ran a debug on poweshell it comes out an error
Source/Player.hx:26: characters 2-13 : Unknown identifier : removeChild
any help would be great, thank you.

package;
import openfl.display.MovieClip;
import openfl.events.Event;
import openfl.Lib;
/**

  • @author Russel Tusay
    */
    class Player
    {
    public var clip1:MovieClip;
    public function new()
    {

    }
    public function anim(){
    clip1.gotoAndStop(2);
    }
    public function func1(){
    if(clip1 != null){
    clip1.x += 1;
    clip1.y = 100;
    }
    }
    public function remove(){
    removeChild(clip1);
    }

}

Maybe you forgot to extend Sprite or extend MovieClip ?


Ok, if that is not the case, the thing is: from where do you want to remove the child? If Player doesn’t extend a Container (like Sprite or MovieClip) you can not remove it from there. You could remove the clip1 from his parent, whoever the parent may be, by doing:
clip1.parent.removeChild(clip1)
This can crash on you if clip1.parent is null, so the safe way is

if (clip1.parent != null) clip1.parent.removeChild(clip1);