• Flex4中使用Path实现画板功能,解决恢复,撤消问题



    近期需要做一个画板的功能,又鉴于SDK3.0的例子,现在都用SDK4.0在开发了,

    3.0里实现的一些在4.0里并不适合使用;

    找了很多相关的资料,也不基于Path实现画板功能

    最近在官方网上看找到一些资料,拿出来分享一下;

    再也不用纠结于 多条lineTo, 难解决操作记录的问题,尤其在解决恢复,撤消问题;

    不多说,贴上代码:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s
    ="library://ns.adobe.com/flex/spark" 
                   xmlns:mx
    ="library://ns.adobe.com/flex/halo"
                   mouseDown
    ="mouseDownHandler(event)"
                   minWidth
    ="1024" minHeight="768">
        
    <s:layout>
            
    <s:BasicLayout/>
        
    </s:layout>
        
    <fx:Declarations>
            
    <!-- Place non-visual elements (e.g., services, value objects) here -->
        
    </fx:Declarations>
        
        
    <fx:Script>
            
    <![CDATA[
                import mx.graphics.SolidColor;
                import mx.graphics.SolidColorStroke;           
                import spark.primitives.Path;           
                private var shape:Path           
                private var pathPoints:Vector.<Point>
                
                private function mouseDownHandler(evt:MouseEvent):void
                {
                    shape = new Path();
                    pathPoints = new <Point>[new Point(evt.localX, evt.localY)];
                    shape.stroke = new SolidColorStroke(0x66CCFF,5,1);
                    this.addElement(shape);
                    this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
                    this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                }
                
                private function mouseMoveHandler(evt:MouseEvent):void
                {
                    pathPoints[pathPoints.length] = new Point(evt.localX, evt.localY);
                    constructPath();
                }
                
                private function mouseUpHandler(evt:MouseEvent):void
                {
                    pathPoints[pathPoints.length] = new Point(evt.localX, evt.localY);
                    constructPath();
                    this.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
                    this.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);                    
                }
                
                private function constructPath():void
                {
                    var dataString = "M "+ pathPoints[0].x +" "+ pathPoints[0].y;
                    for(var i:int=1; i< pathPoints.length; ++i)
                    {
                        var pt:Point = pathPoints[i];
                        dataString += " L "+ pt.x +" "+pt.y;
                    }
                    shape.data = dataString;
                }        
            
    ]]>
        
    </fx:Script>
        
    </s:Application>
  • 相关阅读:
    【校内模拟7.30】—slay(容斥+dp)
    【校内模拟7.30】—slay(容斥+dp)
    【校内模拟7.30】—Ball(bitset)
    【校内模拟7.30】—Ball(bitset)
    多测师讲解rf _基本使用002_高级讲师肖sir
    多测师讲解 自动化测试理论(1)_高级讲师肖sir
    多测师讲解selenium_运行报告相出错归纳_高级讲师肖sir
    多测师讲解selenium—自动化测试课堂面试题总结—高级讲师肖sir
    多测师讲解python _unttest框架002(结合项目实战)_高级讲师肖sir
    多测师讲解python _unttest框架001(基本格式)_高级讲师肖sir
  • 原文地址:https://www.cnblogs.com/dzone/p/2109542.html
Copyright © 2020-2023  润新知