Project 2 Assignment Due Thursday October 8th

Complete Lesson 4 as written except delete the paper in the background and set the background color to #EDEDED, then add a Rect class definition in another .as file. Lesson 4 Addendum

Once completed, modify your lesson 4 to in the following order: step 1, step 2, then step 3. Save each step in with the name yourNameL4step1.fla replacing the 1 with the appropriate step number. Points value for working programs: Step 1-50, 2-25, 3-25. 

  1. Change your Flash file so that mouse movements paint either rectangles or ellipses depending on having pressed either the 'E' or 'R' key.
  2. Create buttons that let users set the size of the shapes that they paint.
  3. Create red, green blue, black, white, and random color buttons that let users choose the color they paint.

var color:Number;
var shapeType:String = "ellipse";

stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

function keyDownHandler(e:KeyboardEvent):void {
    if (e.keyCode == "E".charCodeAt()) {
        shapeType = "ellipse";
    } else if (e.keyCode=="R".charCodeAt()) {
        shapeType = "rectangle";
    }
}

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 {
    if (shapeType == "ellipse") {
        var ellipse:Ellipse = new Ellipse(10, 10, color);
        addChild(ellipse);
        ellipse.x = mouseX;
        ellipse.y = mouseY;
    } else if (shapeType == "rectangle") {
        var rectangle:Rect = new Rect(5, 15, color);
        addChild(rectangle);
        rectangle.x = mouseX;
        rectangle.y = mouseY;
    }
}