早教吧 育儿知识 作业答案 考试题库 百科 知识分享

as3.0中的removeChild的用法我写了以下代码:varanxia:Boolean=falsestage.addEventListener(MouseEvent.MOUSEDOWN,hua)stage.addEventListener(MouseEvent.MOUSEUP,ting)stage.addEventListener(Event.ENTERFRAME,huahua)functionhua(event:MouseEve

题目详情
as3.0中的removeChild的用法
我写了以下代码:
var anxia:Boolean=false
stage.addEventListener(MouseEvent.MOUSE_DOWN,hua)
stage.addEventListener(MouseEvent.MOUSE_UP,ting)
stage.addEventListener(Event.ENTER_FRAME,huahua)
function hua(event:MouseEvent){
anxia=true
}
function ting(event:MouseEvent){
anxia=false
}
function huahua(event:Event){
if (anxia) {
var dian:Sprite=new Sprite()
dian.graphics.lineStyle(0,0x000000)
dian.graphics.beginFill(0x000000)
dian.graphics.drawCircle(0,0,2)
dian.x=mouseX
dian.y=mouseY
addChild(dian)
}
}
可以实现点击鼠标就开始画点直到放开鼠标,但我不懂如何实现放开鼠标后所有点都消失,用removeChild总不成功,只能删除最后放的那个点,具体应该怎样做?
▼优质解答
答案和解析
改成这个样子:
var anxia:Boolean=false
var arr:Array = new Array();
stage.addEventListener(MouseEvent.MOUSE_DOWN,hua)
stage.addEventListener(MouseEvent.MOUSE_UP,ting)
stage.addEventListener(Event.ENTER_FRAME,huahua)
function hua(event:MouseEvent){
anxia=true
}
function ting(event:MouseEvent){
anxia=false
}
function huahua(event:Event){
if (anxia) {
var dian:Sprite=new Sprite()
dian.graphics.lineStyle(0,0x000000)
dian.graphics.beginFill(0x000000)
dian.graphics.drawCircle(0,0,2)
dian.x=mouseX
dian.y=mouseY
this.addChild(dian)
arr.push(dian);
}else{
if(arr.length > 0){
for(var i:int=0;i