# Drawing api and masks

**URL:** <https://forum.kirupa.com/t/drawing-api-and-masks/135022>\
**Category:** Uncategorized\
**Created:** [January 23, 2005, 11:03pm UTC](https://forum.kirupa.com/t/drawing-api-and-masks/135022 "2005-01-23T23:03:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SmurfMX](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SmurfMX](https://forum.kirupa.com/u/SmurfMX)\
**Post date:** [January 23, 2005, 11:03pm UTC](https://forum.kirupa.com/t/drawing-api-and-masks/135022/1 "2005-01-23T23:03:58Z")

</div>

I’ve been having this issue for a day or two now and it’s really bothering me. Sometimes the drawing api draws to the mask perfectly fine other times it doesn’t work at all.

Here’s the code:

```auto

///_quality = "LOW";
var d:Number = 0;
var ptArr:Array = new Array();
_root.flake.setMask(_root.masky);
this.flake.temp = _root.createEmptyMovieClip("container", d);
_root.onMouseDown = function(Void):Void {
	if(this.flake.hitTest( _root._xmouse, _root._ymouse, true)){
		delete ptArr;
		_root.ptArr = new Array();
		//create temp clip to draw in
		this.flake.temp._x = this.flake._x;
		this.flake.temp._y = this.flake._y;
		this.flake.temp.moveTo(this.flake._xmouse, this.flake._ymouse);
		this.flake.temp.lineStyle( 1, 0xFFFFFF, 100);
	}
	
	if(this.flake.hitTest( _root._xmouse, _root._ymouse, true)){
		_root.flake.onMouseMove = function(Void):Void {
			if( this.hitTest( _root._xmouse, _root._ymouse, true) ){
		    	ptArr.push( new Location( this._xmouse, this._ymouse) );
				this.temp.lineTo( this._xmouse, this._ymouse);
			}
		} 
	}
}

_root.onMouseUp = function(Void):Void {
	//kill events
	delete this.flake.onMouseMove;
	
	//close the shape
	this.flake.temp.lineTo( ptArr[0].x, ptArr[0].y );
	trace("Pt arr 0 x: "+ptArr[0].x);
	trace("Pt arr 0 y: "+ptArr[0].y);
	
	//redraw the shape on mask
	var mask:MovieClip = _root.masky;
	mask.moveTo(ptArr[0].x, ptArr[0].y);
	mask.lineStyle( 1, 0xFFFFFF, 100);
	mask.beginFill( 0xFFFFFF, 100)
	if( ptArr[0].x > ptArr[ptArr.length-1].x ){
		trace("If triggered");
		for( var a:Number = 1; a <= ptArr.length-2; a < 5 || a >= ptArr.length-8 ? a++ : a+=3){
			mask.lineTo( ptArr[a].x, ptArr[a].y);
		}
	}else{
		trace("Else triggered");
		for( var a:Number = ptArr.length-1; a > 0; a--){
			mask.lineTo(ptArr[a].x, ptArr[a].y);
		}
	}
	mask.lineTo( ptArr[0].x, ptArr[0].y);
	mask.endFill();
	_root.flake.setMask(mask);
}

```

You can look at it here too [http://smurf2.isolated-designs.net/flake/flake.html](http://smurf2.isolated-designs.net/flake/flake.html) .
