Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:27:11+00:00 2026-05-26T21:27:11+00:00

Possible Duplicate: How to implement Undo and Redo feature in as3 I am going

  • 0

Possible Duplicate:
How to implement Undo and Redo feature in as3

I am going to create an application in that i have to implement an Undo and Redo feature.
In the application there will be multiple objects located on stage and user can customize
the position of the objects. But when user clicks on Undo the object go back to their default
position and after clicking on redo object will move on the new position.

So my question is how can i apply these feature in my application?
Is there any library or any third party classes?

Can some one help me?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:27:11+00:00Added an answer on May 26, 2026 at 9:27 pm

    This seemed like a fun exercise. The following tracks start and end coordinates of display objects, supports undo/redo and destroys redo actions when a new movement is made. It’s probably a bit simple and restrictive for your needs, but could be easily extended by adding to the VO.

    HistoryVO:

    package  {
    
        import flash.display.DisplayObject;
    
        public class HistoryVO {
    
            public var mc:DisplayObject;
            public var oldX:Number;
            public var oldY:Number;
            public var newX:Number;
            public var newY:Number;
    
            public function HistoryVO($mc:DisplayObject,$oldX:Number,$oldY:Number)
            {
                mc = $mc;
                oldX = $oldX;
                oldY = $oldY;
            }
        }
    }
    

    HistoryManager:

    package  {
    
        import flash.display.DisplayObject;
    
        public class HistoryManager {
    
            private var historyList:Vector.<HistoryVO>;
    
            private var tempVO:HistoryVO;
    
            private var index:int;
    
            public function HistoryManager() 
            {
                //initialize the list
                historyList = new Vector.<HistoryVO>();
                index = -1;
            }
    
            public function createEntry($mc:DisplayObject,$oldX:Number,$oldY:Number):void
            {
                //create a tempory VO to store the old position and the object
                tempVO = new HistoryVO($mc,$oldX,$oldY);
            }
    
            public function finishEntry($mc:DisplayObject,$newX:Number,$newY:Number):void
            {
                //make sure this is the same object
                if($mc == tempVO.mc) {
                    tempVO.newX = $newX;
                    tempVO.newY = $newY;
                    if(historyList.length > index+1) {
                        //delete any future history
                        historyList = historyList.splice(0,index+1);
                    }
                    historyList.push(tempVO);
                    index++;
                } else {
                    throw new Error("Target DisplayObject does not match the stored value");
                }
            }
    
            //redo
            public function nextStep():void
            {
                if(historyList.length > index+1) {
                    var step:HistoryVO = historyList[++index];
                    step.mc.x = step.newX;
                    step.mc.y = step.newY;
                }
            }
    
            //undo
            public function previousStep():void
            {
                if(index > -1) {
                    var step:HistoryVO = historyList[index--];
                    step.mc.x = step.oldX;
                    step.mc.y = step.oldY;
                }
            }
        }
    }
    

    Example document class:

    package  {
    
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.display.Sprite;
        import flash.display.MovieClip;
    
        public class Main extends MovieClip {
    
            private var history:HistoryManager;
    
            private var movies:Vector.<Sprite>;
    
            private var backBut:Sprite;
            private var nextBut:Sprite;
    
            public function Main() 
            {
                history = new HistoryManager();
                movies = new Vector.<Sprite>();
                (stage) ? init() : addEventListener(Event.ADDED_TO_STAGE,init);
            }
    
            private function init(evt:Event = null):void
            {
                //create some sprites to play with
                for(var i:int = 0; i < 5; i++) {
                    movies[i] = addChild(new Sprite()) as Sprite;
                    movies[i].x = Math.round(Math.random() * 500);
                    movies[i].y = Math.round(Math.random() * 350);
                    movies[i].graphics.beginFill(Math.round(Math.random()*0xFFFFFF));
                    movies[i].graphics.drawRect(0,0,50,50);
                    movies[i].graphics.endFill();
                    movies[i].addEventListener(MouseEvent.MOUSE_DOWN,onDown);
                    movies[i].addEventListener(MouseEvent.MOUSE_UP,onUp);
                }
                //create the buttons
                backBut = addChild(new Sprite()) as Sprite;
                backBut.graphics.beginFill(0x000000);
                backBut.graphics.drawRect(0,0,100,30);
                backBut.addEventListener(MouseEvent.CLICK,previousStep);
                nextBut = addChild(new Sprite()) as Sprite;
                nextBut.x = 110;
                nextBut.graphics.beginFill(0x000000);
                nextBut.graphics.drawRect(0,0,100,30);
                nextBut.addEventListener(MouseEvent.CLICK,nextStep);
            }
    
            private function onDown(evt:MouseEvent):void
            {
                history.createEntry(Sprite(evt.target),evt.target.x,evt.target.y);
                evt.target.startDrag();
            }
    
            private function onUp(evt:MouseEvent):void
            {
                evt.target.stopDrag();
                history.finishEntry(Sprite(evt.target),evt.target.x,evt.target.y);
            }
    
            private function previousStep(evt:MouseEvent):void
            {
                history.previousStep();
            }
    
            private function nextStep(evt:MouseEvent):void
            {
                history.nextStep();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to create a multiline UITextfield? How can I implement a multiple
Possible Duplicate: How to implement a Map with multiple keys? Imagine a table with
Possible Duplicate: How to implement file upload progress bar on web? Hello I have
Possible Duplicate: How to implement licensing in php downloadable application I am developing a
Possible Duplicate: How do I implement dispatch tables in Perl? I have a hash
Possible Duplicate: WHY an Anonymous class in Java can't implement multiple interfaces directly? Simply
Possible Duplicate: Bayesian networks in MATLAB Is there a toolbox in Matlab which implement
Possible Duplicate: How do you implement a good profanity filter? I have to take
Possible Duplicate: Timeout on a Python function call I want to implement that when
Possible Duplicate: Android: How to overlay-a-bitmap/draw-over a bitmap? I have implement the android Camera

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.