Malerei Flash CS3: Echtzeit-Löschen-Werkzeug
Montag, 11. Februar, 2008 Starten des Codes, die in Erstellen Sie eine Farbe in Flash CS3, Durchführung und kleine Änderungen, können wir deutlich verbessern das Tool auf "löschen". Hinzufügen einer Form nicht sichtbar ist, können Sie es als ein "Plan", um die draw() Fusion-Modus "Löschen". Wie im Beispiel gezeigt, mit etwas konstruiert, halten Sie die Strg-Taste und die Wirkung der "Annullierung" ist jetzt in Echtzeit.
Der Code ist wie folgt - Quelle:
- . MouseEvent ; Import-Blitz. Veranstaltungen. MouseEvent;
- . BitmapData ; Import-Blitz. Anzeige. BitmapData;
- . Bitmap ; Import-Blitz. Anzeige. Bitmap;
- . GradientType ; Import-Blitz. Anzeige. GradientType;
- / /
- . Matrix ; Import-Blitz. Geom.. Matrix;
- / /
- = false ; var md: Boolean = false;
- / /
- Sprite ( ) ; var event_spr: Sprite = new Sprite ();
- ; addChild (event_spr);
- / /
- = event_spr. stage . stageWidth ; var area_width: Number = event_spr. Stadium. stageWidth;
- = event_spr. stage . stageHeight - 32 ; var area_height: Number = event_spr. Stadium. stageHeight - 32;
- / /
- = GradientType. LINEAR ; var fillType: String = GradientType. LINEAR;
- = [ 0xFF0000, 0x00FF00, 0x0000ff ] ; var Farben: Array = [0xFF0000, 0x00FF00, 0x0000ff];
- = [ 1 , 1 , 1 ] ; var Alphas: Array = [1, 1, 1];
- = [ 0 , 128 , 255 ] ; var-Verhältnis: Array = [0, 128, 255];
- = SpreadMethod. PAD ; var spreadMethod: String = SpreadMethod. PAD;
- Matrix ( ) ; var Matrix: Matrix = new Matrix ();
- area_width, area_height, 1 , 0 , 0 ) ; Matrix. createGradientBox (area_width, area_height, 1, 0, 0);
- / /
- event_spr. graphics ) { mit (event_spr. Grafiken) (
- fillType,colors,alphas,ratios,matrix,spreadMethod ) ; beginGradientFill (fillType, Farben, Alphas, Kennzahlen, Matrix, spreadMethod);
- , 0 ,area_width, area_height ) ; drawRect (0, 0, area_width, area_height);
- ; endFill ();
- )
- / / Paint Veranstaltung
- 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 ( event_spr. width ,event_spr. height , true , 0 ) ; var bmpd: BitmapData = new BitmapData (event_spr. Breite, event_spr. Höhe, true, 0);
- Bitmap ( bmpd ) ; var bmp: = new Bitmap Bitmap (bmpd);
- ; addChild (bmp);
- / /
- / / Temporäre Form
- Shape ( ) ; var draw_shape: Shape = new Shape ();
- ; addChild (draw_shape);
- / /
- / / Form, nicht sichtbar, die für die "Abschaffung"
- Shape ( ) ; var erase_shape: Shape = new Shape ();
- / /
- e :MouseEvent ) : void { _onMouseDown Funktion (e: MouseEvent): void (
- ) ; debug ( "_onMouseDown");
- ( 10 , 0xffffff, 1 ) ; draw_shape. Grafiken. LineStyle (10, 0xFFFFFF, 1);
- ( 20 , 0xffffff, 1 ) ; erase_shape. Grafiken. LineStyle (20, 0xFFFFFF, 1);
- ( e . localX , e . localY ) ; draw_shape. Grafiken. moveTo (e. localX, und. localY);
- ( e . localX , e . localY ) ; erase_shape. Grafiken. moveTo (e. localX, und. localY);
- md = true;
- )
- / /
- e :MouseEvent ) : void { _onMouseUp Funktion (e: MouseEvent): void (
- md = false;
- ( draw_shape ) ; bmp. BitmapData. draw (draw_shape);
- ( ) ; draw_shape. Grafiken. clear ();
- ( ) ; erase_shape. Grafiken. clear ();
- )
- / /
- e :MouseEvent ) : void { _onMouseMove Funktion (e: MouseEvent): void (
- ) ; debug ( "_onMouseMove");
- md && ! e . ctrlKey ) { if (MD & &! und. ctrlKey) (
- ( e . localX , e . localY ) ; draw_shape. Grafiken. LineTo (e. localX, und. localY);
- ( md && e . ctrlKey ) { ) Else if (e & & md. CtrlKey) (
- ( e . localX , e . localY ) ; erase_shape. Grafiken. LineTo (e. localX, und. localY);
- ( erase_shape, null , null , "erase" ) ; bmp. BitmapData. draw (erase_shape, null, null, "löschen");
- )
- )
- / /
- v: String ) : void { Debug-Funktion (v: String): void (
- = new Date ( ) ; var d: Datum = new Date ();
- d. getMinutes ( ) + ":" +d. getSeconds ( ) + ":" +d. getMilliseconds ( ) + ": " +v ) ; Trace († getMinutes () + ":" + d. getSeconds () + ":" + d. getMilliseconds () + ":" + v);
- )
Wir haben eine neue Form, erase_shape nicht sichtbar ist (es wurde nicht durchgeführt, alle addChild()
- ...
- / / Form, nicht sichtbar, die für die "Abschaffung"
- Shape ( ) ; var erase_shape: Shape = new Shape ();
Das Stück Code, das versucht zu ziehen wurde für die Steuer-Taste und, wenn gedrückt, ist genau die Frage Shape erase_shape kopiert und auf Bitmap:
- ....
- . lineTo ( e . localX , e . localY ) ; erase_shape. Grafiken. LineTo (e. localX, und. localY);
- ( erase_shape, null , null , "erase" ) ; bmp. BitmapData. draw (erase_shape, null, null, "löschen");






















