LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-23-2009, 02:11 PM
floody123 floody123 is offline
Registered User
 
Join Date: May 2007
Posts: 13
Rep Power: 0
floody123 is on a distinguished road
[CS3] Linestyle, user drawing and issue with variable

Hello,

I'm attempting to make a very simple drawing programme. There will be maybe 4/5 buttons. Three of them when you click on the change the color of the line the user draws. the other two will change the line thickness. I've tried setting up a variable to set to how thick the line should be depending on the button the user has pressed.

But it has no effect - i'm guessing that's because the variable only exists within the confines of the function that I have it in. So how do I allow the variable to exist globally, or am I going the wrong way about this.

Below is the code that has been a class (i'm using as3)....

Code:
 package{
    import flash.display.*;
    import flash.events.MouseEvent;
    
    public class Artist extends Sprite{
    //Are we drawing or not?
    private var drawing:Boolean;
     
    
    public function Artist(){
        
        var color
        var colorNo;
        var colorNo1
        var width1 = 15
        blueButton.addEventListener(MouseEvent.CLICK, blueF)
        blackButton.addEventListener(MouseEvent.CLICK, blackF)
        redButton.addEventListener(MouseEvent.CLICK, redF)
        
        wideButton.addEventListener(MouseEvent.CLICK, wide)
        
        
        function wide()
        {
            width1 = 15
        
        }
        
        
        function blueF()
        {
            colorNo1 = 0x0000FF
            colorNo = 1
            if (colorNo == 1)
        {color = 0x0000FF
        graphic_mc.graphics.lineStyle(width1,color);
        }
        
        
        
            graphic_mc.graphics.lineStyle(width1,color);
            trace ("yes")
            trace (colorNo+"colorNo")
        }
        
        
        function blackF()
        {
            colorNo = 2
            
        if (colorNo == 2)
        {color = 0x000000
        graphic_mc.graphics.lineStyle(width1,color);
        }
        
        
            graphic_mc.graphics.lineStyle(width1,color);
            trace ("yes")
            trace (colorNo+"colorNo")
        }
        
        
        function redF()
        {
            colorNo = 3
            
        if (colorNo == 3)
        {color = 0xFF0000
        graphic_mc.graphics.lineStyle(width1,color);
        }
        
        
            graphic_mc.graphics.lineStyle(width1,color);
            trace ("yes")
            trace (colorNo+"colorNo")
        }
        
        
        graphic_mc.graphics.lineStyle(width1,color);
        drawing = false;//to start with
        stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
        stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
        stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
    }
    
    public function startDrawing(event:MouseEvent):void{
        //move to the correct starting position for drawing
        graphic_mc.graphics.moveTo( mouseX, mouseY);
        drawing = true;
    }
    
        public function draw(event:MouseEvent){
        if(drawing){
            graphic_mc.graphics.lineTo(mouseX,mouseY);
        }
    }
    
        public function stopDrawing(event:MouseEvent){
        drawing = false;
    }
}
}
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT. The time now is 04:22 AM.