. -, Vector ( , , ), , Vector . /, , , , /Redos.
The second approach is to save only what has changed in this vector, so you do not have to create and clone a lot of objects, but save only one object in Vector, which will contain all the properties that have changed and their last values. This will give you something like this:
private var mHistory:Vector.<Object> = new Vector.<Object>();
private var mCurrentIndex:int = -1;
public function storeState(state:Object)
{
mHistory.push(state);
mCurrentIndex++;
}
public function undo():void
{
if(mCurrentIndex < 1)
return;
mCurrentIndex--;
var item:DisplayObject = this.getChildByName(mHistory[mCurrentIndex].name);
if(mHistory[mCurrentIndex].x != undefined)
item.x = mHistory[mCurrentIndex].x;
}
And the function call storeStatewill be like this:
var state:Object = { name:DisplayObjectName, x:120, y:20 };
storeState(state);
Again, you will need to listen to all movements and changes if you want to record them.
source
share