AS2:
lineThickness = 0;
selectedColor = "0x000000";
AS3:
var lineThickness:int = 0;
var selectColor:uint = 0x000000;
AS2:
_root.onMouseDown = startDrawing;
_root.onMouseUp = stopDrawing;
function startDrawing()
{
if(_xmouse < 455)
{
_root.lineStyle(lineThickness, selectedColor);
_root.moveTo(_root._xmouse, _root._ymouse);
_root.onMouseMove = drawLine;
}
}
function stopDrawing()
{
delete this.onMouseMove;
}
function drawLine()
{
_root.lineTo(this._xmouse, this._ymouse);
}
AS3:
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
function startDrawing(e:MouseEvent):void
{
if(mouseX < 455)
{
this.graphics.lineStyle(lineThickness, selectedColor);
this.graphics.moveTo(mouseX, mouseY);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
}
}
function stopDrawing(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
}
function mouseMove(e:MouseEvent):void
{
this.graphics.lineTo(mouseX, mouseY);
}
AS2:
line0.onPress = function()
{
lineThickness = 0;
}
line3.onPress = function()
{
lineThickness = 3;
}
line6.onPress = function()
{
lineThickness = 6;
}
colorRed.onPress = function()
{
selectedColor = "0xFF0000";
}
colorGreen.onPress = function()
{
selectedColor = "0x00FF00";
}
AS3:
line0.addEventListener(MouseEvent.CLICK, changeLine);
line3.addEventListener(MouseEvent.CLICK, changeLine);
line6.addEventListener(MouseEvent.CLICK, changeLine);
colorRed.addEventListener(MouseEvent.CLICK, changeColor);
colorGreen.addEventListener(MouseEvent.CLICK, changeColor);
function changeLine(e:MouseEvent):void
{
switch(e.currentTarget)
{
default: lineThickness = 1; break;
case line0: lineThickness = 0; break;
case line3: lineThickness = 0; break;
case line6: lineThickness = 0; break;
}
}
function changeColor(e:MouseEvent):void
{
switch(e.currentTarget)
{
default: selectedColor = 0x000000;
case colorRed: selectedColor = 0xFF0000; break;
case colorGreen: selectedColor = 0x00FF00; break;
}
}
附加(清除圖形):
eraser_btn.addEventListener(MouseEvent.CLICK, erase);
function erase(e:MouseEvent):void
{
this.graphics.clear();
}
我複製了您的代碼並測試了閃存,並且收到了一條錯誤消息,指出「1120:訪問未定義的屬性selectedColor」。我需要以某種方式定義它嗎? – Learn123 2012-07-24 01:25:16
我更正了1120錯誤。當您在頂部聲明變量時,您鍵入selectColor而不是selectedColor。但是,我現在收到一條錯誤消息:錯誤#1063:paintcanvas_fla :: MainTimeline/stopDrawing()上的參數計數不匹配。預計0,得到1.這是什麼意思? – Learn123 2012-07-24 01:34:22
@ Learn123哎呀,在'stopDrawing()'中添加'e:MouseEvent'。 – Marty 2012-07-24 01:35:33