[AS3]as3代码写的一个画板功能的实例源代码
[AS3]as3代码写的一个画板功能的实例源代码
- package
- {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- public class Main extends Sprite
- {
- private var ceng:Sprite;
- private var isdown:Boolean = false; //默认鼠标未按下
- private var linesize:uint = 2; //CuPlayer.com笔触粗细
- private var oldx:Number; //记录上一个点的X坐标位置
- private var oldy:Number; //记录上一个点的Y坐标位置
- private var changeSize:Sprite; //改变笔尖大小的按钮
- private var fontsize:TextField; //改变笔尖大小的按钮上的文字
- private var sizes:uint = 2; //初始的笔尖大小
- private var colors:Number = 0x000000; //初始的笔尖颜色
- public function Main():void
- {
- init();
- }
- private function init():void
- {
- ceng = new Sprite();
- this.addChild(ceng);
- stage.addEventListener(MouseEvent.MOUSE_DOWN,ondown); //鼠标按下
- stage.addEventListener(MouseEvent.MOUSE_MOVE,onmove); //鼠标移动
- stage.addEventListener(MouseEvent.MOUSE_UP,onup); //鼠标抬起
- //------------------------------------------------
- changeSize = new Sprite();
- changeSize.graphics.beginFill(0x000000,0.5);
- changeSize.graphics.drawRect(10,10,120,30);
- changeSize.graphics.endFill();
- this.addChild(changeSize);
- fontsize = new TextField();
- fontsize.text = "CuPlayer.com红色,变粗,清理舞台";
- fontsize.textColor = 0xff0000;
- fontsize.x = 20;
- fontsize.y = 15;
- changeSize.addChild(fontsize);
- fontsize.addEventListener(MouseEvent.CLICK,changes);
- //-----------------------------------------------
- }
- private function changes(evt:MouseEvent):void
- {
- sizes = 6;
- colors = 0xff0000;
- ceng.graphics.clear();
- }
- private function ondown(evt:MouseEvent):void
- {
- isdown = true; //CuPlayer.com设为鼠标已按下
- oldx = stage.mouseX; //当前鼠标按下那一刻,所在舞台的X坐标
- oldy = stage.mouseY; //当前鼠标按下那一刻,所在舞台的y坐标
- }
- private function onmove(evt:MouseEvent):void
- {
- //CuPlayer.com如果鼠标已按下
- if(isdown)
- {
- ceng.graphics.lineStyle(sizes, colors);
- ceng.graphics.moveTo(oldx, oldy); //CuPlayer.com开始绘图的起始点
- ceng.graphics.lineTo(stage.mouseX, stage.mouseY); //CuPlayer.com绘图的终点坐标
- //更新一下坐标数据(用本次绘制的终点坐标替换,成为下一次绘制的起点坐标)
- oldx = stage.mouseX;
- oldy = stage.mouseY;
- }
- }
- private function onup(evt:MouseEvent):void
- {
- isdown = false; //设为鼠标抬起
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...