Gradient line matrix

Hi, I’m making a lens flare effect, and I want to make a gradient line. The matrix has the right angle, but it does some weird stuff when you try to draw a line.
Here is my code:


function drawgline(x1,y1,x2,y2,bounds:Rectangle):Shape {
	var a:Shape = new Shape();
	a.graphics.beginFill(0xFF0000);
	a.graphics.drawCircle(x1,y1,1);
	a.graphics.drawCircle(x2,y2,1);
	a.graphics.endFill();
	addChild(a);
	var mat:Matrix = new Matrix();
	mat.createGradientBox(bounds.width,bounds.height,Math.atan2(y2-y1,x2-x1),bounds.left,bounds.right);
	var sh:Shape = new Shape();
	sh.graphics.lineStyle(1);
	sh.graphics.lineGradientStyle(GradientType.LINEAR,[0xFFFFFF,0xFFFFFF,0xFFFFFF],[0,1,0],[0,50,100],mat);
	sh.graphics.moveTo(x1,y1);
	sh.graphics.lineTo(x2,y2);
	sh.filters = [new GlowFilter(0xFFFFFF,1,2,2)];
	a = sh;
	a.graphics.beginFill(0xFF0000);
	a.graphics.drawCircle(x1,y1,1);
	a.graphics.drawCircle(x2,y2,1);
	a.graphics.endFill();
	return sh;
}

Most of the code is for debugging.
It’s called like:
flare.addChild(drawgline(Math.cos(ang)*radius,Math.sin(ang)*radius,Math.cos(ang+Math.PI)radius,Math.sin(ang+Math.PI)radius,new Rectangle(-radius,-radius,radius2,radius2)));