我为特定的movieclip创建了事件监听器。在这个movieclip中有很多对象。当我点击父动画片段时,事件监听器会调用子对象的函数。我曾尝试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);}
我想删除mc的父级
答案 0 :(得分:1)
要从其父级中删除mc
显示对象,您可以执行以下操作:
function onMCClick(e:MouseEvent):void
{
var target:DisplayObject = e.target as DisplayObject;
var parent:DisplayObjectContainer = target.parent;
parent.removeChild(target);
}// end function
您还可以通过执行以下操作来删除添加到目标对象的事件侦听器:
function onMCClick(e:MouseEvent):void
{
var target:DisplayObject = e.target as DisplayObject;
target.removeEventListener(MouseEvent.CLICK,onMouseClick);
}// end function
答案 1 :(得分:0)
最后我得回答......谢谢你......
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"));
}