# Updating Variable As3

**URL:** <https://forum.kirupa.com/t/updating-variable-as3/250894>\
**Category:** flash\
**Created:** [February 3, 2008, 1:15am UTC](https://forum.kirupa.com/t/updating-variable-as3/250894 "2008-02-03T01:15:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![le\_shal](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@le\_shal](https://forum.kirupa.com/u/le_shal)\
**Post date:** [February 3, 2008, 1:15am UTC](https://forum.kirupa.com/t/updating-variable-as3/250894/1 "2008-02-03T01:15:52Z")

</div>

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

```auto

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;
        
        }
    
    
}

```
