我有一个功能,我想要删除EventListener
,但它给了我以下错误:
Access of undefined property event
以下是相关代码:
dr_line.addEventListener(MouseEvent.CLICK,drawln);
var test:Boolean;
function drawln(e:MouseEvent):void{
event.currentTarget.removeEventListener(MouseEvent.CLICK, drawln);
stage.addEventListener(MouseEvent.CLICK,click1);
}
var sx,sy,fx,fy,j:int;
function click1(e:MouseEvent):void{
sx=mouseX;
sy=mouseY;
stage.addEventListener(MouseEvent.CLICK,click2);
}
function click2(e:MouseEvent):void{
var i:int;
i=1;
trace(i);
fx=mouseX;
fy=mouseY;
var line:Shape = new Shape();
line.graphics.beginFill(0x00FF00);
line.graphics.moveTo(sx,sy);
line.graphics.lineTo(fx,fy);
this.addChild(line);
}
我尝试在click1
和click2
中删除事件监听器,但它仍然无法正常工作。
我做错了什么?
答案 0 :(得分:2)
事件; e是。尝试更改此内容:
function drawln(e:MouseEvent):void{
event.currentTarget.removeEventListener(MouseEvent.CLICK, drawln);
stage.addEventListener(MouseEvent.CLICK,click1);
}
到此:
function drawln(e:MouseEvent):void{
e.currentTarget.removeEventListener(MouseEvent.CLICK, drawln);
stage.addEventListener(MouseEvent.CLICK,click1);
}
甚至可能是这样:
function drawln(e:MouseEvent):void{
dr_line.removeEventListener(MouseEvent.CLICK, drawln);
stage.addEventListener(MouseEvent.CLICK,click1);
}