Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 如何在as3中实现撤消和重做功能_Flash_Actionscript 3_Apache Flex_Flash Builder_Flash Cs5 - Fatal编程技术网

Flash 如何在as3中实现撤消和重做功能

Flash 如何在as3中实现撤消和重做功能,flash,actionscript-3,apache-flex,flash-builder,flash-cs5,Flash,Actionscript 3,Apache Flex,Flash Builder,Flash Cs5,我将创建一个应用程序,因为我必须实现一个撤消和重做功能。 在应用程序中,舞台上将有多个对象,用户可以自定义 对象的位置。但当用户单击“撤消”时,对象将返回其默认值 位置,单击“重做”后,对象将移动到新位置 所以我的问题是如何在我的应用程序中应用这些特性? 是否有任何图书馆或任何第三方课程 有人能帮我吗 提前谢谢。请看一下。它非常适合于撤消/重做类型的问题。请查看。它非常适合于撤销/重做类型的问题。如果您只需要两种不同的状态(默认状态和“已更改”),那么实现起来应该非常简单。将每个对象的新值和更新

我将创建一个应用程序,因为我必须实现一个撤消和重做功能。 在应用程序中,舞台上将有多个对象,用户可以自定义 对象的位置。但当用户单击“撤消”时,对象将返回其默认值 位置,单击“重做”后,对象将移动到新位置

所以我的问题是如何在我的应用程序中应用这些特性? 是否有任何图书馆或任何第三方课程

有人能帮我吗


提前谢谢。

请看一下。它非常适合于撤消/重做类型的问题。

请查看。它非常适合于撤销/重做类型的问题。

如果您只需要两种不同的状态(默认状态和“已更改”),那么实现起来应该非常简单。将每个对象的新值和更新值存储在数组中,并在按“撤消”或“重做”时设置相关数组中的位置


如果你需要更复杂的东西,你可以将你所做的一切存储为一个“动作”,它是可撤销的。例如,有一个类(例如“Action”)有几个子类(“Move”、“ChangeColor”等)。它们包含它们执行的更改(我们应该移动多少像素)以及执行操作(移动对象X像素)和撤消操作(移动对象-X像素)的方法。

如果您只需要两种不同的状态(默认和“更改”),实现起来应该非常简单。将每个对象的新值和更新值存储在数组中,并在按“撤消”或“重做”时设置相关数组中的位置


如果你需要更复杂的东西,你可以将你所做的一切存储为一个“动作”,它是可撤销的。例如,有一个类(例如“Action”)有几个子类(“Move”、“ChangeColor”等)。它们包含它们执行的更改(我们应该移动多少像素)以及执行操作(移动对象X像素)和撤消操作(移动对象-X像素)的方法。

我能想到的最简单的方法是创建一个操作对象,其中有旧状态、新状态和更改的对象

每次触发将获得撤消功能的操作时,请在操作对象中填写此数据

单击“撤消”时,恢复到对象的before状态,并将操作推入重做堆栈

这应该能够处理最常见的更改。像delete/undelete这样的东西需要一些额外的调整。我会在删除时放入所有属性,并在处理撤消时使用create函数

我建议使用字符串作为参数和前后状态的值组合,这样您就可以在不更改撤消/重做功能的情况下处理其他功能


这是一种更快速、更肮脏的方法,您也可以使用设计模式和其他人提到的适当的OOP方法来处理此问题。

我能想到的最简单的方法是创建一个动作对象,其中您有旧状态、新状态和已更改的对象

 package com
 {
    import flashx.undo.IOperation;

    public class UndoOperation implements IOperation
    {

    private var _previousX:Number = 0;
    private var _previousY:Number = 0;
    private var _previousObj:Object = new Object();
    private var _currentX:Number = 0;
    private var _currentY:Number = 0;
    private var _currentObj:Object = new Object();
    private var _shape:Object = new Object();


    public function TransformOperation(currentObj:Object,previousObj:Object,previousX:Number, previousY:Number, currentX:Number, currentY:Number)
    {
        _previousX = previousX;
        _previousY = previousY;
        _previousObj = previousObj;

        _currentX = currentX;
        _currentY = currentY;
        _currentObj = currentObj;
        _shape = _currentObj;

        trace('Transform _previousX:  '+  _previousX  +' _previousY:  ' +_previousY+' _currentObj '+_currentObj+' _shape '+_shape);
        trace( 'trans _currentX    '+ _currentX +'  '+'_currentY     '+ _currentY );

    }

    public function performUndo():void
    {
        _shape = _currentObj;
        //trace('_shape.x '+_shape.x+" _shape.y "+_shape.y);
        _shape.x = _previousX;
        _shape.y = _previousY;
        //trace(_previousX +'  '+ _previousY +'  '+ _previousWidth +'  '+ _previousHeight +'  '+  _previousScaleX +'  '+  _previousScaleY +'  '+ _previousRotation);
        //trace('_shape.x '+_shape.x+" _shape.y "+_shape.y);
        //trace('_currentX    '+ _currentX +'  '+'_currentY     '+ _currentY);
    }

    public function performRedo():void
    {
        _shape.x = _currentX;
        _shape.y = _currentY;
        trace(_currentX+'  '+ _currentY);
    }
  }
}
每次触发将获得撤消功能的操作时,请在操作对象中填写此数据

单击“撤消”时,恢复到对象的before状态,并将操作推入重做堆栈

这应该能够处理最常见的更改。像delete/undelete这样的东西需要一些额外的调整。我会在删除时放入所有属性,并在处理撤消时使用create函数

我建议使用字符串作为参数和前后状态的值组合,这样您就可以在不更改撤消/重做功能的情况下处理其他功能

这是一种更快速、更肮脏的方法,您也可以使用设计模式和适当的OOP方法来处理它,正如其他人所提到的

 package com
 {
    import flashx.undo.IOperation;

    public class UndoOperation implements IOperation
    {

    private var _previousX:Number = 0;
    private var _previousY:Number = 0;
    private var _previousObj:Object = new Object();
    private var _currentX:Number = 0;
    private var _currentY:Number = 0;
    private var _currentObj:Object = new Object();
    private var _shape:Object = new Object();


    public function TransformOperation(currentObj:Object,previousObj:Object,previousX:Number, previousY:Number, currentX:Number, currentY:Number)
    {
        _previousX = previousX;
        _previousY = previousY;
        _previousObj = previousObj;

        _currentX = currentX;
        _currentY = currentY;
        _currentObj = currentObj;
        _shape = _currentObj;

        trace('Transform _previousX:  '+  _previousX  +' _previousY:  ' +_previousY+' _currentObj '+_currentObj+' _shape '+_shape);
        trace( 'trans _currentX    '+ _currentX +'  '+'_currentY     '+ _currentY );

    }

    public function performUndo():void
    {
        _shape = _currentObj;
        //trace('_shape.x '+_shape.x+" _shape.y "+_shape.y);
        _shape.x = _previousX;
        _shape.y = _previousY;
        //trace(_previousX +'  '+ _previousY +'  '+ _previousWidth +'  '+ _previousHeight +'  '+  _previousScaleX +'  '+  _previousScaleY +'  '+ _previousRotation);
        //trace('_shape.x '+_shape.x+" _shape.y "+_shape.y);
        //trace('_currentX    '+ _currentX +'  '+'_currentY     '+ _currentY);
    }

    public function performRedo():void
    {
        _shape.x = _currentX;
        _shape.y = _currentY;
        trace(_currentX+'  '+ _currentY);
    }
  }
}
这是我的自定义类,用于撤消和重做舞台上的多个对象。有不同的模式可用于撤销和重做操作,但对我来说,这是撤销和重做的简单方法。我已经在我的项目中完美且成功地实现了这一点

若要使用该类,请仅导入该类

                 import flashx.undo.UndoManager;
然后呢

            public static var _undo:UndoManager=new UndoManager();
            public static var _redo:UndoManager=new UndoManager();     
            public static var PrevX:Number=0;
            public static var PrevY:Number=0;
            var operation:TransformOperation = new TransformOperation(this,this,PrevX,PrevY,this.x,this.y);
           _undo.pushUndo(operation);
之后,创建撤消和重做的单击事件:

    public static function Undo(e:MouseEvent):void
    {
        _redo.pushRedo(_undo.peekUndo());
        _undo.undo();
        if(_undo.peekUndo()==null)
        {
            PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("undo_mc").removeEventListener(MouseEvent.CLICK,Undo);
        }
        PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("redo_mc").addEventListener(MouseEvent.CLICK,Redo);
    }

    public static function Redo(e:MouseEvent):void
    {
        _undo.pushUndo(_redo.peekRedo());
        _redo.redo();
        if(_redo.peekRedo()==null)
        {                          PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("redo_mc").removeEventListener(MouseEvent.CLICK,Redo);
        }
        PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("undo_mc").addEventListener(MouseEvent.CLICK,Undo);
    }
对我来说这很好用。。。希望这对其他人也有帮助…:)

这是我的自定义类,用于撤消和重做舞台上的多个对象。有不同的模式可用于撤销和重做操作,但对我来说,这是撤销和重做的简单方法。我已经在我的项目中完美且成功地实现了这一点

若要使用该类,请仅导入该类

                 import flashx.undo.UndoManager;
然后呢

            public static var _undo:UndoManager=new UndoManager();
            public static var _redo:UndoManager=new UndoManager();     
            public static var PrevX:Number=0;
            public static var PrevY:Number=0;
            var operation:TransformOperation = new TransformOperation(this,this,PrevX,PrevY,this.x,this.y);
           _undo.pushUndo(operation);
之后,创建撤消和重做的单击事件:

    public static function Undo(e:MouseEvent):void
    {
        _redo.pushRedo(_undo.peekUndo());
        _undo.undo();
        if(_undo.peekUndo()==null)
        {
            PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("undo_mc").removeEventListener(MouseEvent.CLICK,Undo);
        }
        PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("redo_mc").addEventListener(MouseEvent.CLICK,Redo);
    }

    public static function Redo(e:MouseEvent):void
    {
        _undo.pushUndo(_redo.peekRedo());
        _redo.redo();
        if(_redo.peekRedo()==null)
        {                          PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("redo_mc").removeEventListener(MouseEvent.CLICK,Redo);
        }
        PlayerPosition.getClass.getChildByName("toolbar_mc").getChildByName("undo_mc").addEventListener(MouseEvent.CLICK,Undo);
    }

对我来说这很好用。。。希望这对其他人也有帮助…:)

命令模式本身是不够的。通常它与-pattern一起使用。命令模式本身是不够的。通常它与-pattern一起使用。你能提供一些代码块让我继续吗?你能提供一些代码块让我继续吗?如何实现多个对象的撤消和重做?在as3中可以有任何第三方类吗?如何实现多个对象的撤销和重做?我们可以在as3上第三方课程吗?