Flash As3.0 绘制线条

package
{

import flash.display.Sprite;

import flash.events.MouseEvent;
import flash.events.Event;
import fl.controls.ColorPicker;//导入组件ColorPicker的包
import flash.display.LineScaleMode;//为下面绘制线条指定笔触粗细缩放属性导入包(LineScaleMode.NORMAL 默认值)
import flash.display.CapsStyle;//为下面绘制线条指定线条末端处端点类型的属性导入包(CapsStyle.ROUND 默认值)
import fl.events.ColorPickerEvent;//为事件ColorPickerEven导入包

 

public class lines extends Sprite
{
private var myShape:Sprite;//
private var colorPicker:ColorPicker;
private var getColor:uint;
public function lines()
{
stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownHandler);//为舞台添加鼠标按下事件
stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUpHandler);//为舞台添加鼠标弹起事件
colorPicker = new ColorPicker();
colorPicker.x = 20;
colorPicker.y = 20;
addChild(colorPicker);//将组件添加到舞台上
colorPicker.addEventListener(ColorPickerEvent.CHANGE, changeHandler);//为组件ColorPicker添加CHANGE事件

}
private function changeHandler(e:ColorPickerEvent):void
{


getColor = uint("0x"+e.target.hexValue) ;//将组件ColorPicker的颜色值转换为16进制
trace(getColor);


}

private function onMouseDownHandler(e:MouseEvent):void
{


myShape = new Sprite();
myShape.graphics.moveTo(mouseX,mouseY);//确定绘制线条的起点为鼠标按下是的坐标
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);


}

 


private function onMouseUpHandler(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);

}
private function onMouseMoveHandler(e:MouseEvent):void
{
//myShape.graphics.clear();
myShape.graphics.lineStyle(1,getColor,1,true,LineScaleMode.NONE,CapsStyle.NONE );//设置线条样式

//myShape.graphics.lineBitmapStyle(new Photo(0,0));//指定一个位图,用于绘制线条时的线条笔触。 在调用 lineBitmapStyle() 方法之前调用 lineStyle() 方法以启用笔触,图片入库


myShape.graphics.lineTo(mouseX,mouseY);//确定绘制线条的终点为鼠标弹起时的坐标并连接
stage.addChild(myShape);//将线条添加到舞台上
}
}

}

posted @ 2012-10-22 22:17  流年亂了浮生  阅读(2140)  评论(0编辑  收藏  举报