zoukankan      html  css  js  c++  java
  • Flash/Flex学习笔记(14):制作涂鸦板

    关键点:知道如何画线就行了,代码不复杂,直接看吧(从同事一本书上抄的)

    view source

    print?

    01
    var drawing:Boolean;

    02

    03
    Mouse.hide(); //隐藏默认的光标

    04

    05
    stage.addEventListener(MouseEvent.MOUSE_MOVE,Stage_MouseMove);

    06
    stage.addEventListener(MouseEvent.MOUSE_DOWN,Stage_MouseDown);

    07
    stage.addEventListener(MouseEvent.MOUSE_UP,Stage_MouseUp);

    08
    stage.addEventListener(KeyboardEvent.KEY_DOWN,Stage_KeyDown);

    09

    10
    function Stage_MouseDown(e:MouseEvent):void {

    11
    this.graphics.moveTo(this.mouseX,this.mouseY);//设置划线的起点

    12
    this.graphics.lineStyle(3,0x99cc00,100);//设置笔触大小及颜色

    13
    drawing=true;

    14
    }

    15

    16

    17
    function Stage_MouseMove(e:MouseEvent):void {

    18
    //铅笔鼠标跟随

    19
    pen1.x=this.mouseX;

    20
    pen1.y=this.mouseY;

    21

    22
    if (drawing) {

    23
    this.graphics.lineTo(this.mouseX,this.mouseY);//关键代码就在这里

    24
    }

    25
    e.updateAfterEvent();

    26
    }

    27

    28
    function Stage_MouseUp(e:MouseEvent):void {

    29
    drawing=false;

    30
    }

    31

    32
    function Stage_KeyDown(e:KeyboardEvent):void {

    33
    if (e.keyCode==Keyboard.DELETE) { //注意这里:虽然代码只写了Delete键,但实际测试中发现如果按Ctrl + Delete组合键,也能触发

    34
    this.graphics.clear();

    35
    }

    36
    }

    做为对比,大家也可以参看:silverlight:手写板/涂鸦/墨迹/InkPresenter示例程序

  • 相关阅读:
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    tctip demo页面>
    sql 随笔
  • 原文地址:https://www.cnblogs.com/happysky97/p/1884498.html
Copyright © 2011-2022 走看看