0 Replies - 2506 Views - Last Post: 27 February 2013 - 11:20 PM

#1 nash13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-February 13

How to applay undo and redo function?

Posted 27 February 2013 - 11:20 PM

Can anyone show me how can I make undo and redo function? so this is my current actionscript. it dose not work the way i want it. i hoping it work just line undo and redo function in windows paint. 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. pls help i am still new with action script 3...

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);







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{



    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


     if (shapes.length>MAX_UNDO) shapes.unshift(); // drop oldest state



function undo():void {

    if (position>0) {



    } // else can't undo


function redo():void {

    if (position+1<shapes.length) {



    } // else can't redo




 function btn_undo(e:MouseEvent):void





 function btn_redo(e:MouseEvent):void





undo_btn.addEventListener(MouseEvent.CLICK, btn_undo);

redo_btn.addEventListener(MouseEvent.CLICK, btn_redo);

Is This A Good Question/Topic? 0
  • +

Page 1 of 1