1
http://www.haogongju.net/art/623801
2 // 主容器
3 var main:Sprite = new Sprite();
4 main.mouseEnabled = false ;
5 addChild(main)
6 // 临时容器(所有操作都将先画在临时容器里,再进行"画"或"擦")
7 var mc:Sprite = new Sprite()
8 main.addChild(mc)
9 // 保存最终画出来的内容的bitmapdata
10 var content:BitmapData = new BitmapData( 550 , 400 , true , 0x00FFFFFF );
11 // 把content显示出来
12 var show:Bitmap = new Bitmap(content)
13 main.addChildAt(show, 0 )
14
15 // 默认选中画笔
16 var action:Number = 0
17 txt.text = " 当前选中:画笔 "
18
19
20 mc_move.addEventListener(MouseEvent.MOUSE_DOWN,startDraw)
21 a.addEventListener(MouseEvent.CLICK,changeAction)
22 b.addEventListener(MouseEvent.CLICK,changeAction)
23 function changeAction(e:MouseEvent): void
24 {
25 if (e.target.name == " a " )
26 {
27 action = 0
28 txt.text = " 当前选中:画笔 "
29 mc.visible = true
30 } else
31 {
32 action = 1
33 txt.text = " 当前选中:橡皮 "
34 mc.visible = false
35 }
36 }
37 function startDraw(e:MouseEvent): void
38 {
39 mc.graphics.lineStyle( 20 ,cp.selectedColor);
40 mc.graphics.moveTo(mouseX,mouseY);
41 mc_move.addEventListener(MouseEvent.MOUSE_MOVE,drawing);
42 stage.addEventListener(MouseEvent.MOUSE_UP,stopDraw);
43 }
44 function stopDraw(e:MouseEvent): void
45 {
46 if (action != 1 )content.draw(mc, new Matrix(), new ColorTransform(),BlendMode.NORMAL, new Rectangle( 0 , 0 , 550 , 400 ))
47 mc.graphics.clear()
48 mc_move.removeEventListener(MouseEvent.MOUSE_MOVE,drawing);
49 stage.removeEventListener(MouseEvent.MOUSE_UP,stopDraw);
50 }
51 function drawing(e:MouseEvent): void
52 {
53 mc.graphics.lineTo(mouseX,mouseY)
54 if (action == 1 )content.draw(mc, new Matrix(), new ColorTransform(),BlendMode.ERASE)
55 e.updateAfterEvent()
56 }
57
58
2 // 主容器
3 var main:Sprite = new Sprite();
4 main.mouseEnabled = false ;
5 addChild(main)
6 // 临时容器(所有操作都将先画在临时容器里,再进行"画"或"擦")
7 var mc:Sprite = new Sprite()
8 main.addChild(mc)
9 // 保存最终画出来的内容的bitmapdata
10 var content:BitmapData = new BitmapData( 550 , 400 , true , 0x00FFFFFF );
11 // 把content显示出来
12 var show:Bitmap = new Bitmap(content)
13 main.addChildAt(show, 0 )
14
15 // 默认选中画笔
16 var action:Number = 0
17 txt.text = " 当前选中:画笔 "
18
19
20 mc_move.addEventListener(MouseEvent.MOUSE_DOWN,startDraw)
21 a.addEventListener(MouseEvent.CLICK,changeAction)
22 b.addEventListener(MouseEvent.CLICK,changeAction)
23 function changeAction(e:MouseEvent): void
24 {
25 if (e.target.name == " a " )
26 {
27 action = 0
28 txt.text = " 当前选中:画笔 "
29 mc.visible = true
30 } else
31 {
32 action = 1
33 txt.text = " 当前选中:橡皮 "
34 mc.visible = false
35 }
36 }
37 function startDraw(e:MouseEvent): void
38 {
39 mc.graphics.lineStyle( 20 ,cp.selectedColor);
40 mc.graphics.moveTo(mouseX,mouseY);
41 mc_move.addEventListener(MouseEvent.MOUSE_MOVE,drawing);
42 stage.addEventListener(MouseEvent.MOUSE_UP,stopDraw);
43 }
44 function stopDraw(e:MouseEvent): void
45 {
46 if (action != 1 )content.draw(mc, new Matrix(), new ColorTransform(),BlendMode.NORMAL, new Rectangle( 0 , 0 , 550 , 400 ))
47 mc.graphics.clear()
48 mc_move.removeEventListener(MouseEvent.MOUSE_MOVE,drawing);
49 stage.removeEventListener(MouseEvent.MOUSE_UP,stopDraw);
50 }
51 function drawing(e:MouseEvent): void
52 {
53 mc.graphics.lineTo(mouseX,mouseY)
54 if (action == 1 )content.draw(mc, new Matrix(), new ColorTransform(),BlendMode.ERASE)
55 e.updateAfterEvent()
56 }
57
58