谁能告诉我怎样才能让撤消和重做功能?所以这是我目前的动作脚本。我无法弄清楚如何做到这一点,我看到在一些网站上的一些例子中,动作脚本是长下架。 PLS显示一个简单的方法,我可以使这项工作。
抱歉语法错误...
进口的flash.display.MovieClip;
进口flash.events.MouseEvent;
VAR pen_mc:影片剪辑;
VAR图:布尔= FALSE;
变种penSize:UINT = 1;
VAR penColor:数= 0x000000处;
VAR形状:矢量<形状和GT =新矢量<形状和GT;();
VAR位置:= 0;
常量MAX_UNDO:INT = 10;
功能的init():无效{
pen_mc =新的MovieClip();
stage.addEventListener(的MouseEvent.MOUSE_DOWN,startDrawing);
stage.addEventListener(的MouseEvent.MOUSE_MOVE,isDrawing);
stage.addEventListener(侦听MouseEvent.MOUSE_UP,finishedDrawing);
的addChild(pen_mc);
}
在里面();
功能startDrawing(E:的MouseEvent):无效{
跟踪(笔开始画);
拉丝= TRUE;
pen_mc.graphics.lineStyle(penSize,penColor);
pen_mc.graphics.moveTo(mouseX,mouseY的);
}
功能isDrawing(E:的MouseEvent):无效{
如果(图){
pen_mc.graphics.lineTo(mouseX,mouseY的);
}
}
功能finishedDrawing(E:的MouseEvent):无效{
跟踪(完成绘制);
拉丝= FALSE;
VAR SH:形状=新形状();
sh.graphics.copyFrom(pen_mc.graphics); //把当前状态到载体
shapes.push(SH);
如果(shapes.length> MAX_UNDO)shapes.unshift(); //下降最古老的国家
位置= shapes.indexOf(SH);
}
功能undo():无效{
如果(位置大于0){
位置 - ;
pen_mc.graphics.copyFrom(形状[位置] .graphics);
} //否则无法撤消
}
功能重做():无效{
如果(位置+ 1< shapes.length){
位置++;
pen_mc.graphics.copyFrom(形状[位置] .graphics);
} //否则不能重做
}
功能btn_undo(E:MouseEvent)方法:无效
{
撤消();
}
功能btn_redo(E:MouseEvent)方法:无效
{
重做();
}
undo_btn.addEventListener(MouseEvent.CLICK,btn_undo);
redo_btn.addEventListener(MouseEvent.CLICK,btn_redo);
解决方案
您可以使用的copyfrom()
在Shape.graphics存储当前的状态,同样以重做,为你的画布是一个形状。
VAR形状:。矢量<形状和GT =新矢量<形状和GT;();
VAR位置:= 0;
常量MAX_UNDO:INT = 10;
...
功能finishedDrawing(E:的MouseEvent):无效{
跟踪(完成绘制);
拉丝= FALSE;
VAR SH:形状=新形状();
sh.graphics.copyFrom(penMC.graphics); //把当前状态到载体
shapes.push(SH);
如果(shapes.length> MAX_UNDO)shapes.unshift(); //下降最古老的国家
位置= shapes.indexOf(SH);
}
功能undo():无效{
如果(位置大于0){
位置 - ;
penMC.graphics.copyFrom(形状[位置] .graphics);
} //否则无法撤消
}
功能重做():无效{
如果(位置+ 1< shapes.length){
位置++;
penMC.graphics.copyFrom(形状[位置] .graphics);
} //否则不能重做
}
![韦东山uboot 内核 根文件系统学习笔记5.1 5.3 第005课 字符设备驱动 第001 003节 字符设备驱动程序之概念介绍 字符设备驱动程序之LED驱动程序 编写编译](https://p.xsw88.cn/allimgs/daicuo/20230908/1090.png)
这做法缺乏一些功能,如放弃撤销/重做堆栈的一部分,如果第一个百废待兴到某一点,然后绘制。你可以尝试添加这个功能吧。
Can anyone show me how can I make undo and redo function? so this is my current action script. I cant figure how to do it and i see some example in some web site, the action script is to long to under stand. Pls show a simple way that i can make this work..
sorry for bad grammar...
import flash.display.MovieClip;
import flash.events.MouseEvent;
var pen_mc:MovieClip;
var drawing:Boolean = false;
var penSize:uint = 1;
var penColor:Number = 0x000000;
var shapes:Vector.<Shape>=new Vector.<Shape>();
var position:int=0;
const MAX_UNDO:int=10;
function init():void{
pen_mc = new MovieClip();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, isDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, finishedDrawing);
addChild(pen_mc);
}
init();
function startDrawing(e:MouseEvent):void{
trace("Pen Has started drawing");
drawing = true;
pen_mc.graphics.lineStyle(penSize, penColor);
pen_mc.graphics.moveTo(mouseX, mouseY);
}
function isDrawing(e:MouseEvent):void{
if(drawing){
pen_mc.graphics.lineTo(mouseX, mouseY);
}
}
function finishedDrawing(e:MouseEvent):void{
trace("finished drawing");
drawing = false;
var sh:Shape=new Shape();
sh.graphics.copyFrom(pen_mc.graphics); // put current state into the vector
shapes.push(sh);
if (shapes.length>MAX_UNDO) shapes.unshift(); // drop oldest state
position=shapes.indexOf(sh);
}
function undo():void {
if (position>0) {
position--;
pen_mc.graphics.copyFrom(shapes[position].graphics);
} // else can't undo
}
function redo():void {
if (position+1<shapes.length) {
position++;
pen_mc.graphics.copyFrom(shapes[position].graphics);
} // else can't redo
}
function btn_undo(e:MouseEvent):void
{
undo();
}
function btn_redo(e:MouseEvent):void
{
redo();
}
undo_btn.addEventListener(MouseEvent.CLICK, btn_undo);
redo_btn.addEventListener(MouseEvent.CLICK, btn_redo);
解决方案
You can use copyFrom()
in Shape.graphics to store current condition, and the same to "redo", as your canvas is a Shape.
var shapes:Vector.<Shape>=new Vector.<Shape>();
var position:int=0;
const MAX_UNDO:int=10;
...
function finishedDrawing(e:MouseEvent):void{
trace("finished drawing");
drawing = false;
var sh:Shape=new Shape();
sh.graphics.copyFrom(penMC.graphics); // put current state into the vector
shapes.push(sh);
if (shapes.length>MAX_UNDO) shapes.unshift(); // drop oldest state
position=shapes.indexOf(sh);
}
function undo():void {
if (position>0) {
position--;
penMC.graphics.copyFrom(shapes[position].graphics);
} // else can't undo
}
function redo():void {
if (position+1<shapes.length) {
position++;
penMC.graphics.copyFrom(shapes[position].graphics);
} // else can't redo
}
This approach lacks some features, as to drop part of undo/redo stack if first undone to a certain point, then drawn. You can try adding this function yourself.
相关推荐
最新文章