Hello,
I’m trying to create a drawing App with AS3 and I’m having trouble getting the pen variable to update with the new size. I’m not sure where the problem is.
I have a variable defined at the beginning of the script (lineSize) and a function that is supposed to increase the variable by 1 each time a button is clicked. It is increasing the variable, but its not updating the actual lineSize variable.
Any help would be appreaciated,
Shal
import flash.geom.*
import flash.display.*
import flash.events.*
//pen variable
var lineSize:int = 1
var colors:uint = 0x27B5F1;
//define new shape
var pen = new Shape();
//drawing variables
var doDraw:Boolean=false;
//pen
pen.graphics.beginFill(colors);
pen.graphics.drawCircle(-10,-10,lineSize);
//define drawing area
var canvas:BitmapData = new BitmapData(407, 375,false, 0x00FFFFFF)
var penBM:Bitmap = new Bitmap(canvas);
penBM.x=10;
penBM.y=10;
addChild(penBM);
//add event listeners and functions for drawing
stage.addEventListener(MouseEvent.MOUSE_DOWN,penDown);
stage.addEventListener(MouseEvent.MOUSE_UP,penUp);
function penDown(e:MouseEvent):void {
trace("DOWN")
doDraw=true;
addEventListener(Event.ENTER_FRAME, penEnter);
}
function penUp(e:MouseEvent):void {
trace("UP")
doDraw=false;
removeEventListener(Event.ENTER_FRAME, penEnter);
}
function penEnter(event:Event):void
{
canvas.draw(pen,new Matrix(1,0,0,1,this.mouseX,this.mouseY),null,'layer');
}
//event listener and function for clearing graphics
btnErase.addEventListener(MouseEvent.CLICK, eraseClicked);
function eraseClicked(e:MouseEvent):void
{
trace("CLEAR")
canvas.fillRect(canvas.rect,0x00FFFFFF)
}
btnUp.addEventListener(MouseEvent.CLICK, upClicked);
function upClicked(e:MouseEvent):void {
if(lineSize<20){
lineSize+=1;
trace(lineSize);
} else {
lineSize=20;
}
}