explanation: im working on a drawing app for android and im stuck on a undo feature.
the feature relies on a array of my layer arrays, each one added whenever someone makes a “pencil” stroke
I then, when the back button is pressed, delete my canvas and its data, then redraw with a old version(from the past) then delete the old version.
My problem is, whenever I add a new stroke every single, every value of my undo array is replaced with the new version.
my code:
code for the adding of the stroke to the undo list:
stage.removeChild(temp);
this.addChild(path);
startdrawing=true
layerarray[0].draw(path,null,null,null,null,true);
path.parent.removeChild(path);
var templayers:Array= new Array(layerarray[0],layerarray[1])
undolist[undolist.length]=templayers
code for the canvas update:
if(e.keyCode==Keyboard.BACK){
trace(undolist.length)
trace(undolist[undolist.length-1])
trace(undolist[undolist.length-1][0].getPixel(0,0))
layerarray=new Array();
layerarray=undolist.pop()
display.parent.removeChild(display)
display=new MovieClip();
disparray=new Array();
disparray[0]=new Bitmap(layerarray[0]);
disparray[1]=new Bitmap(layerarray[1]);
display.name='hello world'
display.x=330;
display.y=100;
display.scaleX=0.7;
display.scaleY=0.7;
display.addChildAt(disparray[0],0)
display.addChildAt(disparray[1],1)
this.addChildAt(display,0);
}