好的,想法很简单,舞台上的一组按钮,点击按钮改变颜色来绘制。我正在尝试学习 flash 和 actionscript,但不确定我的问题出在哪里,但我不知道该怎么做。
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Artist extends Sprite {
public var drawing:Boolean;
public var colorArray:Array;
public var dc;
public function colors() {
colorArray = ["0xFF0000","0xFFA500","0xFFFF00","0x00FF00","0x0000FF","0x4B0082","0x8F00FF","0xFF69B4","0x00CCFF","0x008000","0x8B4513"];
for (var i:int = 0; i < colorArray.length; i++) {
this["btn_" + i].addEventListener(MouseEvent.CLICK, set_color);
}
}
public function set_color(e:MouseEvent):void {
dc = colorArray;
}
public function Artist() {
graphics.lineStyle(10,dc);
drawing = false;
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
}
public function startDrawing(event:MouseEvent):void {
graphics.moveTo( mouseX, mouseY);
drawing = true;
}
public function draw(event:MouseEvent) {
if(drawing) {
graphics.lineTo(mouseX,mouseY);
}
}
public function stopDrawing(event:MouseEvent) {
drawing = false;
}
}
}