本のActionscript教室のレッスン4の例に従っていますが、ステージにCLEARボタンを追加して変更しています。
すべての機能が機能するかどうかをテストするときはいつでも、ボタンの上に描画することができます。理想的には、ユーザーが描画しているとき、色はボタンの下に表示されている必要があります。
タイムラインには、背景、ボタン、アクションのレイヤーがあります。問題にすばやく対処できるように、以下のコーディングを追加しました。ありがとう!
package {
import flash.display.MovieClip;
public class Ellipse extends MovieClip {
// constructor
public function Ellipse(w:Number=40,h:Number=40,color:Number=0xff0000) {
graphics.beginFill(color);
graphics.drawEllipse(0, 0, w, h);
graphics.endFill();
}
} // end class Ellipse
} // end package
import flash.events.MouseEvent;
var color:Number;
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
function startDrawing(e:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE, makeShapes);
color = Math.random() * 0xFFFFFF;
}
function stopDrawing(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, makeShapes);
}
function makeShapes(e:MouseEvent):void {
var ellipse:Ellipse = new Ellipse(10, 10, color);
stage.addChild(ellipse);
ellipse.x = mouseX;
ellipse.y = mouseY;
}
btnClear.addEventListener(MouseEvent.CLICK, clearBoard);
function clearBoard(e:MouseEvent)
{
for (var i:int = stage.numChildren-1; i >= 1; i--) {
stage.removeChildAt (i);
}
}