# Help me understand functions & scope

**URL:** https://forum.kirupa.com/t/help-me-understand-functions-scope/195951
**Category:** flash
**Created:** [August 4, 2006, 5:26am UTC](https://forum.kirupa.com/t/help-me-understand-functions-scope/195951 "2006-08-04T05:26:54Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![angusf](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@angusf](https://forum.kirupa.com/u/angusf)
#### Post date: [August 4, 2006, 5:26am UTC](https://forum.kirupa.com/t/help-me-understand-functions-scope/195951/1 "2006-08-04T05:26:54Z")

</div>

I still don’t always get it ☹

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?

```auto

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.
