I'm only getting one level of undo with pop method / undo button
Hi. Why does this code only produce one level of undo? I thought each time the pop method is triggered on an array the array shrinks and you can continue to pop as long as the array is not less than 0.
Here's my code:
import flash.display.MovieClip;
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.events.Event;
//http://www.kirupa.com/forum/showthread.php?309502-As3-Spiral-effect .. this is the one used previously in other files
//http://hub.tutsplus.com/tutorials/create-a-basic-drawing-application-in-flash--active-1627 .. this is the one used here
var my_mc:MovieClip=new MC();
var container:MovieClip=new MovieClip();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
var shape:Shape=new Shape();
var myArr:Array=new Array();
var myArrRedo:Array = new Array();
var myArrObj:Array= new Array();
var undo_btn:MovieClip=new Btn_mc_undo();
var redo_btn:MovieClip=new Btn_mc_redo();
undo_btn.x=10;
undo_btn.y=350;
redo_btn.x=110;
redo_btn.y=undo_btn.y;
addChild(undo_btn);
addChild(container);
stage.addChild(redo_btn);
var nums:int;
undo_btn.addEventListener(MouseEvent.MOUSE_DOWN, undoEvent);
redo_btn.addEventListener(MouseEvent.MOUSE_DOWN, redoEvent);
function undoEvent(e:MouseEvent):void{
container.removeChild(myArrObj.pop());
}
function redoEvent(e:MouseEvent):void{
// nothing yet
}
var num:int=0;
function startDrawing(e:MouseEvent):void{
shape=new Shape();
container.addChild(shape);
shape.name=String(num);
myArr.push(shape.name);
myArrObj.push(shape);
shape.graphics.lineStyle(3, 0xcccccc);
shape.graphics.moveTo(mouseX, mouseY);
stage.addEventListener(MouseEvent.MOUSE_MOVE, whileDrawing);
num++;
}
function stopDrawing(e:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, whileDrawing);
}
function whileDrawing(e:MouseEvent):void{
shape.graphics.lineTo(mouseX, mouseY);
}
a couple of these lines are left over from troubleshooting (such as the num++);
