A partir de los códigos proporcionados en Paint Crear una aplicación en Flash CS3 , y realizar pequeños ajustes, usted puede mejorar dramáticamente el instrumento de "borrar". Adición de una forma no visible, se puede utilizar como un "plan" para ejecutar el draw() en el modo de fusión "borrar". Como se muestra en el ejemplo siguiente, después de dibujar algo, mantenga presionada la tecla Ctrl y el efecto de la "anulación" aparece ahora en tiempo real.
El código es el siguiente - fuente :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | . MouseEvent ; flash.events importación. MouseEvent ; . BitmapData ; import flash.display. BitmapData ; . Bitmap ; importar flash.display. mapa de bits ; . GradientType ; import flash.display. GradientType ; / / . Matrix ; . importación flash.geom Matrix ; / / Boolean = false ; var md: Boolean = false; / / Sprite = new Sprite ( ) ; var event_spr: Sprite = new Sprite (); event_spr ) ; addChild (event_spr); / / Number = event_spr . stage . stageWidth ; var area_width: Número .. = event_spr prácticas stageWidth; Number = event_spr . stage . stageHeight - 32 ; var area_height: Número .. = event_spr prácticas stageHeight - 32; / / String = GradientType . LINEAR ; fillType var: Cadena = GradientType LINEAL;. : Array = [ 0xFF0000 , 0x00FF00 , 0x0000ff ] ; colores var: matriz = [0xFF0000, 0x00FF00, 0x0000FF]; : Array = [ 1 , 1 , 1 ] ; alfas var: matriz = [1, 1, 1]; : Array = [ 0 , 128 , 255 ] ; proporciones var: matriz = [0, 128, 255]; String = SpreadMethod . PAD ; spreadMethod var: Cadena = SpreadMethod PAD;. : Matrix = new Matrix ( ) ; var matriz: Matrix = new Matrix (); createGradientBox ( area_width , area_height , 1 , 0 , 0 ) ; . matriz createGradientBox (area_width, area_height, 1, 0, 0); / / event_spr . graphics ) { con (event_spr. gráficos) { fillType , colors , alphas , ratios , matrix , spreadMethod ) ; beginGradientFill (fillType, colores, alfas, relaciones, matriz, SpreadMethod); 0 , 0 , area_width , area_height ) ; drawRect (0, 0, area_width, area_height); ; endFill (); } / / Pintura evento ( MouseEvent . MOUSE_DOWN , _onMouseDown ) ; . event_spr addEventListener ( MouseEvent MOUSE_DOWN, _onMouseDown.); ( MouseEvent . MOUSE_MOVE , _onMouseMove ) ; . event_spr addEventListener ( MouseEvent MOUSE_MOVE, _onMouseMove.); ( MouseEvent . MOUSE_UP , _onMouseUp ) ; . event_spr addEventListener ( MouseEvent MOUSE_UP, _onMouseUp.); ( MouseEvent . MOUSE_OUT , _onMouseUp ) ; . event_spr addEventListener ( MouseEvent MOUSE_OUT, _onMouseUp.); / / BitmapData = new BitmapData ( event_spr . width , event_spr . height , true , 0 ) ; var bmpd: BitmapData = new BitmapData (ancho event_spr., event_spr altura, es cierto, 0.); Bitmap = new Bitmap ( bmpd ) ; var bmp: Bitmap = new Bitmap (bmpd); bmp ) ; addChild (bmp); / / Forma / / Temporal Shape = new Shape ( ) ; var draw_shape: Shape = new Shape (); draw_shape ) ; addChild (draw_shape); / / / / Forma, no visible, que se utiliza para la "cancelación" Shape = new Shape ( ) ; var erase_shape: Shape = new Shape (); / / e : MouseEvent ) : void { función _onMouseDown (e: MouseEvent ): void { ) ; debug ("_onMouseDown"); . lineStyle ( 10 , 0xffffff , 1 ) ; .. draw_shape gráficos lineStyle (10, 0xffffff, 1); . lineStyle ( 20 , 0xffffff , 1 ) ; .. erase_shape gráficos lineStyle (20, 0xffffff, 1); . moveTo ( e . localX , e . localY ) ; .. draw_shape gráficos moveTo (E. localX, y localY.); . moveTo ( e . localX , e . localY ) ; .. erase_shape gráficos moveTo (E. localX, y localY.); md = true; } / / e : MouseEvent ) : void { función _onMouseUp (e: MouseEvent ): void { md = false; . draw ( draw_shape ) ; .. bmp bitmapData empate (draw_shape); . clear ( ) ; draw_shape gráficos clear ()..; . clear ( ) ; erase_shape gráficos clear ()..; } / / e : MouseEvent ) : void { función _onMouseMove (e: MouseEvent ): void { ) ; debug ("_onMouseMove"); md && ! e . ctrlKey ) { if (&& md! e. ctrlKey) { . lineTo ( e . localX , e . localY ) ; .. draw_shape gráficos lineTo (E. localX, y localY.); ( md && e . ctrlKey ) { } Else if (&& md e. CtrlKey) { . lineTo ( e . localX , e . localY ) ; .. erase_shape gráficos lineTo (E. localX, y localY.); . draw ( erase_shape , null , null , "erase" ) ; bmp bitmapData draw (erase_shape, null, null, "erase")..; } } / / v : String ) : void { debug función (v: Cadena ): void { : Date = new Date ( ) ; var d: Date = new Date (); d . getMinutes ( ) + ":" + d . getSeconds ( ) + ":" + d . getMilliseconds ( ) + ": " + v ) ; trace (d. getMinutes () + ":" + d getSeconds () + ":" + d getMilliseconds () + ":".. + v); } |
): Hemos añadido una nueva forma, erase_shape , no visible (no se ha hecho ningún addChild() ):
1 2 3 |
En el código que se encarga del dibujo se ha introducido para controlar la tecla Ctrl, cuando se pulsa, se refiere precisamente la forma erase_shape y copiados al mapa de bits:
1 2 3 | .... . lineTo ( e . localX , e . localY ) ; .. erase_shape gráficos lineTo (E. localX, y localY.); . draw ( erase_shape , null , null , "erase" ) ; bmp bitmapData draw (erase_shape, null, null, "erase")..; |










A Mejora de las palancas en Mí and function del drenaje Hizo una Clase.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
. Sprite ; import flash.display. Sprite ;
. MouseEvent ; flash.events importación. MouseEvent ;
. BitmapData ; import flash.display. BitmapData ;
. Bitmap ; importar flash.display. mapa de bits ;
. GradientType ; import flash.display. GradientType ;
. SpreadMethod ; import flash.display. SpreadMethod ;
. Shape ; importar flash.display. Forma ;
. Matrix ; . importación flash.geom Matrix ;
. setInterval ; flash.utils importación setInterval.;
. clearInterval ; flash.utils importación clearInterval.;
BitmapErase extends Sprite { Public class BitmapErase extiende Sprite {
md : Boolean = false ; private var md: Boolean = false;
event_spr : Sprite ; private var event_spr: Sprite ;
area_width : Number ; area_width var privado: Número ;
area_height : Number ; area_height var privado: Número ;
fillType : String = GradientType . LINEAR ; fillType private var: Cadena = GradientType . LINEAL;
colors : Array = [ 0xFF0000 , 0x00FF00 , 0x0000ff ] ; colores var privadas: matriz = [0xFF0000, 0x00FF00, 0x0000FF];
alphas : Array = [ 1 , 1 , 1 ] ; alfas privadas var: matriz = [1, 1, 1];
ratios : Array = [ 0 , 128 , 255 ] ; var relaciones privadas: matriz = [0, 128, 255];
spreadMethod : String = SpreadMethod . PAD ; private var spreadMethod: Cadena = SpreadMethod PAD;.
matrix : Matrix = new Matrix ( ) ; var matriz privada: Matrix = new Matrix ();
erase_shape : Shape ; erase_shape private var: Forma ;
draw_shape : Shape ; draw_shape private var: Forma ;
bmpd : BitmapData ; private var bmpd: BitmapData ;
bmp : Bitmap ; private var bmp: mapa de bits ;
interval : uint ; intervalo de private var: uint ;
BitmapErase ( ) { Función pública BitmapErase () {
( ) ; draw_shape = new Shape ();
draw_shape ) ; addChild (draw_shape);
( ) ; erase_shape = new Shape ();
( ) ; event_spr = new Sprite ();
event_spr ) ; addChild (event_spr);
. stageWidth ; . area_width = event_spr prácticas stageWidth.;
. stageHeight - 32 ; .. area_height = event_spr prácticas stageHeight - 32;
createGradientBox ( area_width , area_height , 1 , 0 , 0 ) ; . matriz createGradientBox (area_width, area_height, 1, 0, 0);
. beginGradientFill ( fillType , colors , alphas , ratios , matrix , spreadMethod ) ; .. event_spr gráficos beginGradientFill (fillType, colores, alfas, relaciones, matriz, SpreadMethod);
. drawRect ( 0 , 0 , area_width , area_height ) ; .. event_spr gráficos drawRect (0, 0, area_width, area_height);
. endFill ( ) ; . event_spr gráficos endFill ().;
( MouseEvent . MOUSE_DOWN , _onMouseDown ) ; . event_spr addEventListener ( MouseEvent MOUSE_DOWN, _onMouseDown.);
( MouseEvent . MOUSE_MOVE , _onMouseMove ) ; . event_spr addEventListener ( MouseEvent MOUSE_MOVE, _onMouseMove.);
( MouseEvent . MOUSE_UP , _onMouseUp ) ; . event_spr addEventListener ( MouseEvent MOUSE_UP, _onMouseUp.);
( MouseEvent . MOUSE_OUT , _onMouseUp ) ; . event_spr addEventListener ( MouseEvent MOUSE_OUT, _onMouseUp.);
( event_spr . width , event_spr . height , true , 0 ) ; bmpd = new BitmapData (ancho event_spr., event_spr altura, es cierto, 0.);
( bmpd ) ; bmp = new Bitmap (bmpd);
bmp ) ; addChild (bmp);
}
_onMouseDown ( e : MouseEvent ) : void { _onMouseDown private function (e: MouseEvent ): void {
/ / Debug ("_onMouseDown");
. lineStyle ( 10 , 0xffffff , 1 ) ; .. draw_shape gráficos lineStyle (10, 0xffffff, 1);
. lineStyle ( 20 , 0xffffff , 1 ) ; .. erase_shape gráficos lineStyle (20, 0xffffff, 1);
. moveTo ( e . localX , e . localY ) ; .. draw_shape gráficos moveTo (E. localX, y localY.);
. moveTo ( e . localX , e . localY ) ; .. erase_shape gráficos moveTo (E. localX, y localY.);
md = true;
}
_onMouseUp ( e : MouseEvent ) : void { función _onMouseUp privada (e: MouseEvent ): void {
md = false;
. clear ( ) ; draw_shape gráficos clear ()..;
. clear ( ) ; erase_shape gráficos clear ()..;
interval ) ; clearInterval (intervalo);
}
_onMouseMove ( e : MouseEvent ) : void { función _onMouseMove privada (e: MouseEvent ): void {
/ / Debug ("_onMouseMove");
md && ! e . ctrlKey ) { if (&& md! e. ctrlKey) {
. lineTo ( e . localX , e . localY ) ; .. draw_shape gráficos lineTo (E. localX, y localY.);
drawNow , 1 ) ; interval = setInterval (drawNow, 1);
( md && e . ctrlKey ) { } Else if (&& md e. CtrlKey) {
. lineTo ( e . localX , e . localY ) ; .. erase_shape gráficos lineTo (E. localX, y localY.);
. draw ( erase_shape , null , null , "erase" ) ; bmp bitmapData draw (erase_shape, null, null, "erase")..;
}
}
debug ( v : String ) : void { debug función privada (v: Cadena ): void {
: Date = new Date ( ) ; var d: Date = new Date ();
d . getMinutes ( ) + ":" + d . getSeconds ( ) + ":" + d . getMilliseconds ( ) + ": " + v ) ; trace (d. getMinutes () + ":" + d getSeconds () + ":" + d getMilliseconds () + ":".. + v);
}
drawNow ( ) : void { función privada drawNow (): void {
. draw ( draw_shape ) ; .. bmp bitmapData empate (draw_shape);
}
}
}
@ Greg: ¡Bien!
Esto es totalmente increíble! Gran trabajo. ¿Es posible tener la misma cosa aquí, excepto que está borrando un movieclip exponer la imagen de fondo por debajo de ella?
Esto es totalmente increíble! Gran trabajo. Usted puede tener la misma cosa aquí, excepto que está suprimiendo un clip de la película que expone la imagen de fondo?