我想知道如何阻止用户在学校董事会外面画画。
我的电路板图像尺寸为709.15 X 499.5。 所以我想到了这样的事情......
if(stage.stageWidth <= 709)
但如果我的电路板图像在舞台 boardActiva 上被称为变量,那么应该更容易。
以下是绘制的函数:
private function dibujar(e:MouseEvent){
trace(e.localY);
tizaActiva.x = e.stageX;
tizaActiva.y = e.stageY;
if(dibujando){
tabla.graphics.lineTo(e.stageX,e.stageY);
}
这是完整的代码:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.*;
import flash.trace.Trace;
import flash.ui.Mouse;
import flash.display.Shape;
import fl.controls.ColorPicker;
import fl.motion.Color;
import fl.events.ColorPickerEvent;
public class pizarra extends MovieClip {
private var colores:ColorPicker = new ColorPicker;
private var boardActiva:board = new board;
private var tizaActiva:tiza = new tiza();
private var tabla:Shape = new Shape;
private var dibujando:Boolean;
public function pizarra() {
Mouse.hide();
tabla.graphics.lineStyle(5,0xFFFFFF);
// constructor code
boardActiva.x = 45;
boardActiva.y = 40;
addChild(boardActiva);
addChild(tabla);
addChild(colores);
addChild(tizaActiva);
dibujando = false;
stage.addEventListener(MouseEvent.MOUSE_DOWN, empezarDibujo);
stage.addEventListener(MouseEvent.MOUSE_MOVE, dibujar);
stage.addEventListener(MouseEvent.MOUSE_UP, detenerDibujo);
colores.addEventListener(ColorPickerEvent.CHANGE,cambiar);
}
private function empezarDibujo(e:MouseEvent):void{
trace(e.localY);
tabla.graphics.moveTo(e.stageX,e.stageY);
dibujando = true;
}
private function dibujar(e:MouseEvent){
trace(e.localY);
tizaActiva.x = e.stageX;
tizaActiva.y = e.stageY;
if(dibujando){
tabla.graphics.lineTo(e.stageX,e.stageY);
}
}
private function detenerDibujo(e:MouseEvent){
trace(e.localY);
dibujando = false;
}
private function cambiar(e:ColorPickerEvent){
tabla.graphics.lineStyle(5,e.color);
}
}
}
答案 0 :(得分:1)
如果我理解你的问题,应该这样做:
private function dibujar(e:MouseEvent)
{
//trace(e.localY);
tizaActiva.x = e.stageX;
tizaActiva.y = e.stageY;
if(dibujando && insideBoard(e.stageX,e.stageY) )
{
tabla.graphics.lineTo(e.stageX,e.stageY);
}
}
private function insideBoard(x:Number,y:Number):Boolean
{
return ( (x>= boardActiva.x)
&& (x <= boardActiva.x + boardActiva.width )
&& (y >= boardActiva.y)
&& (y <= boardActiva.y + boardActiva.height ) );
}
希望得到一些帮助,祝你的pizarra好运;)