Help me understand functions & scope

I still don’t always get it :frowning:

How can I access the “draw” method from the “startDrawing” method below, why is the trace ouput for this code:

Drawing Started
undefined
Drawing Stopped

And once that is solved will the “draw” method be able to call the pen.makeMark method as attempted?


import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.filters.BlurFilter;

class Canvas {
    private var parent_mc:MovieClip;       //MC to attach canvas clip to
    private var drawnCanvas:MovieClip;     //MC to use as canvas
    
    private var onScreenImage:BitmapData;  // image displayed onscreen
    private var offScreenImage:BitmapData; // image drawn into offscreen
    private var blurFilter:BlurFilter;        
    private var pen:PenTool;               // manages nature of pen marks
    
    public function Canvas(target:MovieClip){
        parent_mc = target;
        
        onScreenImage = new BitmapData(200 , 200, true );
        offScreenImage = new BitmapData(200 , 200 , true );
        
        // create the container to hold the bitmap at a certain location
        drawnCanvas = parent_mc._parent.createEmptyMovieClip("drawnCanvas", parent_mc.getNextHighestDepth() );
        drawnCanvas._x = 100;
        drawnCanvas._y = 100;
        
        //functions for mouse events (start/stop drawing)
        drawnCanvas.onPress = startDrawing;
        drawnCanvas.onRelease = drawnCanvas.onReleaseOutside = stopDrawing;
        
        drawnCanvas.attachBitmap(onScreenImage , 1 , "always" , false );
        blurFilter = new BlurFilter( 2 , 2 , 2 );
        pen = new PenTool(60 ,2 ,0x000000);
    }
    
    public function startDrawing() {
        trace("Drawing Started");
        trace(draw);
        drawnCanvas.onMouseMove = draw;
    }
    
    public function stopDrawing() {
        trace("Drawing Stopped");
        delete drawnCanvas.onMouseMove;
    }
    
    public function draw() {
        trace("Drawing");
        pen.makeMark(offScreenImage, new Point( drawnCanvas._xmouse , drawnCanvas._ymouse ) );
        onScreenImage.applyFilter(offScreenImage, new Rectangle( 0 , 0 , 200 , 200 ), new Point( 0 , 0 ), blurFilter );
    }
}

thanks for your help.