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 262509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:31:18+00:00 2026-05-11T22:31:18+00:00

I’m new to AS3 and have been working on an XML driven navigation system

  • 0

I’m new to AS3 and have been working on an XML driven navigation system written in AS3.

At present, I’ve imported the contents of an XML file and plotted it inside a containing MovieClip created at root level dynamically on the stage. This MovieClip is called ‘container’.

What I want to accomplish is a smooth, accelerating / decelerating effect which animates the container movieclip along the X axis depending on where the mouse cursor is in relation to the middle of the stage.

My code can be found here: http://pastie.org/521432

Line 87 onwards is the code I’m using right now to make the movieclip scroll left & right.

What I have does work but is clunky but does work – I just want it to be a little more polished and have drawn a blank with Google. Because I want the MovieClip to continue to scroll at the current relative speed even when the mouse stops moving, I used an instance of the Timer class.

Can anyone suggest improvements? 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-11T22:31:18+00:00Added an answer on May 11, 2026 at 10:31 pm

    You should separate out you calculations and your drawing methods. So have it do all the calculations in an onMouseMove handler, but actually draw the changes in an onEnterFrame handler.

    Also I think your algorithm could be much simpler and nobody would notice. I made a quick example of how you might do it. paste this code into an AS3 file called Main.as and make it the document class of a new FLA.

    package 
    {
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
    
        public class Main extends Sprite 
        {
            private const boxCount:int = 10;
            private const boxWidth:int = 45;
            private const boxMargin:int = 5;
            private const startPoint:int = 150;
            private const boxesWidth:int = boxCount * (boxWidth + boxMargin);
            private const endPoint:int = boxesWidth + startPoint;
            private const zeroPoint:int = boxesWidth / 2 + startPoint;
    
            private var container:MovieClip;
            private var targetX:Number;
            private var speed:Number = 0;
    
            public function Main():void 
            {
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);
            }
    
            private function init(e:Event = null):void 
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
    
                container = new MovieClip();
                addChild(container);
                container.x = 150;
                container.y = 300;
                for (var i:int = 0; i < boxCount; i++) 
                {
                    container.graphics.beginFill(Math.random() * 0xFFFFFF);
                    container.graphics.drawRect(i*(boxWidth+boxMargin), 0, boxWidth, boxWidth);
                }
    
                addEventListener(Event.ENTER_FRAME, enterFrameHandler);
                stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
            }
    
            private function mouseMoveHandler(e:MouseEvent):void 
            {
                var distanceFromCenter:int = stage.mouseX - zeroPoint;
                speed = distanceFromCenter * -0.01; // Bring number into a good range, and invert it.
            }
    
            private function enterFrameHandler(e:Event):void 
            {
                container.x += speed;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.