===========================
在論壇幫人解答的問題答案
功能就是像在Windows內拉選出一個框
可以把畫面上的物件通通刪掉
本來一開始是提供思路給發問的人
後來感覺還是直接寫Code給他比較快
不過因為只是給人參考用,架構我沒有寫得非常嚴謹,也沒做防呆
有興趣的人可以參考參考
===========================
//先配置場景上的物件 var nowthis = this ; //配置畫圖按鈕(紅色) var DrawBtn : MovieClip = new MovieClip(); with(DrawBtn.graphics){ lineStyle(1,0xff0000); beginFill(0xff0000); drawRect(0,0,50,50); } DrawBtn.x = 150 ; DrawBtn.y =350 ; nowthis.addChild(DrawBtn); DrawBtn.buttonMode =true ; //配置清除畫面上畫圖的按鈕(綠色) var ClearBtn : MovieClip = new MovieClip(); with(ClearBtn.graphics){ lineStyle(1,0x00ff00); beginFill(0x00ff00); drawRect(0,0,50,50); } ClearBtn.x = 250 ; ClearBtn.y =350 ; nowthis.addChild(ClearBtn); ClearBtn.buttonMode = true ; //配置裝圖形的畫布 var Paint : MovieClip = new MovieClip(); nowthis.addChild(Paint); //用來當畫圖容器的物件 var DrawObj : MovieClip ; var ClearDrawObj : MovieClip ; //====================================================== //場景布置完成,開始事件 DrawBtn.addEventListener(MouseEvent.CLICK,DrawHandler); function DrawHandler(me:MouseEvent):void{ stage.addEventListener(MouseEvent.MOUSE_DOWN,DrawNow); } function DrawNow(me:Event):void{ if (me.type == 'enterFrame'){ with (DrawObj.graphics){ clear(); lineStyle(1); beginFill(0x666666); moveTo(DrawObj.Sx,DrawObj.Sy); lineTo(DrawObj.Sx,Paint.mouseY); lineTo(Paint.mouseX,Paint.mouseY); lineTo(Paint.mouseX,DrawObj.Sy); lineTo(DrawObj.Sx,DrawObj.Sy); } }else if (me.type == 'mouseDown'){ DrawObj = new MovieClip(); DrawObj.Sx = Paint.mouseX; DrawObj.Sy = Paint.mouseY; Paint.addChild(DrawObj); stage.removeEventListener(MouseEvent.MOUSE_DOWN,DrawNow); stage.addEventListener(MouseEvent.MOUSE_UP,DrawNow); stage.addEventListener(Event.ENTER_FRAME,DrawNow); }else if (me.type == 'mouseUp'){ stage.removeEventListener(MouseEvent.MOUSE_UP,DrawNow); stage.removeEventListener(Event.ENTER_FRAME,DrawNow); } } ClearBtn.addEventListener(MouseEvent.CLICK,ClearHandler); function ClearHandler(me:MouseEvent):void{ stage.addEventListener(MouseEvent.MOUSE_DOWN, ClearNow); } function ClearNow(me:Event):void{ if (me.type == 'enterFrame'){ with (ClearDrawObj.graphics){ clear(); lineStyle(1); beginFill(0x66ff66); moveTo(ClearDrawObj.Sx,ClearDrawObj.Sy); lineTo(ClearDrawObj.Sx,Paint.mouseY); lineTo(Paint.mouseX,Paint.mouseY); lineTo(Paint.mouseX,ClearDrawObj.Sy); lineTo(ClearDrawObj.Sx,ClearDrawObj.Sy); } for(var i : int = 0 ; i < Paint.numChildren ; i++){ var TmpObj = Paint.getChildAt(i); if (TmpObj.hitTestObject(ClearDrawObj)){ TmpObj.alpha = .5 ; }else{ TmpObj.alpha = 1; } } }else if (me.type == 'mouseDown'){ ClearDrawObj = new MovieClip(); ClearDrawObj.Sx = Paint.mouseX; ClearDrawObj.Sy = Paint.mouseY; Paint.addChild(ClearDrawObj); stage.removeEventListener(MouseEvent.MOUSE_DOWN,ClearNow); stage.addEventListener(MouseEvent.MOUSE_UP,ClearNow); stage.addEventListener(Event.ENTER_FRAME,ClearNow); }else if (me.type == 'mouseUp'){ stage.removeEventListener(MouseEvent.MOUSE_UP,ClearNow); stage.removeEventListener(Event.ENTER_FRAME,ClearNow); var ClearArr :Array= [] ; for (i = 0 ; i < Paint.numChildren ; i++){ TmpObj = Paint.getChildAt(i); if (TmpObj.alpha != 1){ ClearArr.push(TmpObj); } } for (i = 0 ; i < ClearArr.length ; i++){ Paint.removeChild(ClearArr[i]); } } }
|
===========================
留言列表