Reputation: 443
I have created event listeners for a particular movieclip.Insidet this movieclip there is so many objects.When ever i click on the parent movieclip the event listener calls the function for the child object. I had tried removeEventLIstener()
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
var info:MovieClip=new MovieClip();
info.graphics.beginFill(0x000000,0.35);
info.graphics.drawCircle(0,0,300);
var mc:MovieClip=new MovieClip();
mc.graphics.beginFill(0x000000,0.5);
mc.graphics.drawCircle(0,0,30);
this.addChild(info);
mc.x=0;
mc.y=0;
info.x=stage.stageWidth/2
info.y=stage.stageHeight/2;
info.addChild(mc);
mc.addEventListener(MouseEvent.CLICK,msclick);
function msclick(e:MouseEvent):void{
e.target.removeChild(e.target.parent);}
i want to delete mc's parent
Upvotes: 0
Views: 4551
Reputation: 443
FINALLY I GOT ANSWER ...THANKYOU GUYS..........
import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent;
var info:MovieClip=new MovieClip();
info.graphics.beginFill(0x000000,0.35);
info.graphics.drawCircle(0,0,300);
var mc:MovieClip=new MovieClip();
mc.graphics.beginFill(0x000000,0.5);
mc.graphics.drawCircle(0,0,30);
this.addChild(info);
mc.x=0;
mc.y=0;
info.x=stage.stageWidth/2
info.y=stage.stageHeight/2;
mc.name="222";
info.addChild(mc);
mc.addEventListener(MouseEvent.CLICK,msclick);
function msclick(e:MouseEvent):void{
trace(info.getChildByName("222"));
info.getChildByName("222").x+=100;
trace(e.target.name)
var ob:Object=getChildByName(e.target.name);
//this.addChild(ob);
info.removeChild(getChildByName("222"));
}
Upvotes: 0
Reputation: 3207
To remove your mc
display object from its parent, you can do the following:
function onMCClick(e:MouseEvent):void
{
var target:DisplayObject = e.target as DisplayObject;
var parent:DisplayObjectContainer = target.parent;
parent.removeChild(target);
}// end function
You can also remove the event listener added to the target object by doing the following:
function onMCClick(e:MouseEvent):void
{
var target:DisplayObject = e.target as DisplayObject;
target.removeEventListener(MouseEvent.CLICK,onMouseClick);
}// end function
Upvotes: 1