简体   繁体   中英

how to remove parent movieclip from child movieclip ain actionscript 3?

below shows how to add child in a movieclip.
ebd.target.addChild(info_grd);

there is button named my_btn inside the movieclip info_grd .I would like to remove movieclip info_grd.parent

Code would be something like :

delete_btn.addEventListener(MouseEvent.CLICK , del);

function del(e:MouseEvent)
{
    this.parent.removeChildAt(0);
}

what I am doing here is adding a movie clip from library and adding a child to it , when I click on delete it will delete the parent.

var mm:mm1 = new mm1();
//Adding it to stage
addChild(mm);

var m2:mm2 = new mm2();
//adding the child to mm
mm.addChild(m2);

Amir's code assumes there's only one child, and thus won't work when you add more children.

This code will perform the correct behavior:

deleteButton.addEventListener(MouseEvent.CLICK , removeFromParent);

function removeFromParent(event:MouseEvent)
{
    var child:DisplayObject = event.currentTarget as DisplayObject;
    var parent:DisplayObjectContainer = child.parent;

    parent.removeChild(child);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM