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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:05:35+00:00 2026-05-23T11:05:35+00:00

I’ve been searching for hours but still haven’t found the answer to my problem.

  • 0

I’ve been searching for hours but still haven’t found the answer to my problem.

My goal is to have a map that I can drag around within the frame of a webpage.
Finding the right code to move the map in a restricted frame wasn’t too easy but I managed to find that (which works like a charm):

zoom3.addEventListener(MouseEvent.MOUSE_DOWN, dragArea);
zoom3.addEventListener(MouseEvent.MOUSE_UP, dropArea);

function dragArea(e:MouseEvent):void{
var bounds:Rectangle = new Rectangle(
                            stage.stageWidth - zoom3.width, 
                            stage.stageHeight - zoom3.height, 
                            zoom3.width - stage.stageWidth, 
                            zoom3.height - stage.stageHeight
                        );
zoom3.startDrag(false, bounds);
}

function dropArea(e:MouseEvent):void{
zoom3.stopDrag();
}

Now the catch is that I’d like the map to be dragged simultaneously with a movieclip situated above, that contains names of regions, cities etc…
Both can’t be on the same layer as I need to put a layer of texture in between.

Is there a simple way to link both layers and make them move at once?

Hope I’m clear enough, English is my second language.
Thanks for reading, and maybe helping.

  • 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-23T11:05:35+00:00Added an answer on May 23, 2026 at 11:05 am

    you can:

    • add an enterframe event listener when you start the drag (remove it when you stop the drag). track the difference in position with the dragged movieclip and apply it to the second one.
    • override the setters for the x and y of the dragged clip, and either mirror it on the dragged clip, or dispatch an event that the second movieclip listens to and update accordingly

    Option 1:

    private var m_prevX:Number = 0.0;
    private var m_prevY:Number = 0.0;
    
    private function dragArea(e:MouseEvent):void
    {
        var bounds:Rectangle = ...
    
        // hold the current x and y so that we can get the difference
        this.m_prevX = zoom3.x;
        this.m_prevY = zoom3.y;
    
        // add the enterframe listener
        zoom3.addEventListener( Event.ENTER_FRAME, this._onEnterFrame );
    
        // start dragging
        zoom3.startDrag(false, bounds);
    }
    
    private function dropArea(e:MouseEvent):void
    {
        zoom3.stopDrag();
    
        // remove the enter frame listener
        zoom3.removeEventListener( Event.ENTER_FRAME, this._onEnterFrame );
    }
    
    // called every frame that we're dragging
    private function _onEnterFrame( e:Event ):void
    {
        // get the difference in movement
        var diffX:Number = this.m_prevX - zoom3.x;
        var diffY:Number = this.m_prevY - zoom3.y;
    
        // store the current pos
        this.m_prevX = zoom3.x;
        this.m_prevY = zoom3.y;
    
        // apply the difference to the other clip
        myOtherClip.x += diffX;
        myOtherClip.y += diffY;
    }
    

    ** Option “:**
    A more OO approach. You don’t need to override the x and y, but zoom3 needs to extend a class something like this:

    public class DraggableClip extends MovieClip
    {
        /******************************************************/
    
        /**
         * The name of the event that we dispatch when we're being dragged
         * and our position changes
         */
        public static const DRAG_UPDATE_POS:String = "drag_update_pos";
    
        /******************************************************/
    
        /**
         * The x difference in position if we're being dragged
         */
        public var dragDiffX:Number = 0.0;
    
        /**
         * The y difference in position if we're being dragged
         */
        public var dragDiffY:Number = 0.0;
    
        /******************************************************/
    
        private var m_prevX:Number = 0.0; // our previous x position
        private var m_prevY:Number = 0.0; // our previous y position
    
        /******************************************************/
    
        /**
         * Start dragging the clip. This is dispatch an event when
         * our position changes
         */
        override public function startDrag():void
        {
            // reset the drag difference positions
            this.dragDiffX = 0.0;
            this.dragDiffY = 0.0;
    
            // hold our current position
            this.m_prevX = this.x;
            this.m_prevY = this.y;
    
            // add an event listener to that we can track the difference
            // you could also set it to listen to MouseEvent.MOUSE_MOVE if
            // you wanted
            this.addEventListener( Event.ENTER_FRAME, this._onEnterFrame );
    
            // start dragging
            super.startDrag();
        }
    
        /**
         * Stop dragging the clip
         */
        override public function stopDrag():void
        {
            // remove the event listener
            this.removeEventListener( Event.ENTER_FRAME, this._onEnterFrame );
    
            // stop draggin
            super.stopDrag();
        }
    
        /******************************************************/
    
        // called every frame we're updating
        private function _onEnterFrame( e:Event ):void
        {
            // get the drag difference
            this.dragDiffX = this.m_prevX - this.x;
            this.dragDiffY = this.m_prevY - this.y;
    
            // store the current x and y
            this.m_prevX = this.x;
            this.m_prevY = this.y;
    
            // if our position has changed, dispatch an event
            if( this.dragDiffX != 0.0 && this.dragDiffY != 0.0 )
                this.dispatchEvent( new Event( DraggableClip.DRAG_UPDATE_POS ) );
        }
    }
    

    Then to listen to the events, something like this:

    private function _init():void
    {
        // do your init stuff
        zoom3       = new DraggableClip;
        myOtherClip = new MovieClip;
    
        // add the event listener to zoom3
        zoom3.addEventListener( DraggableClip.DRAG_UPDATE_POS, this._onDragZoom3 );
    }
    
    private function _onDragZoom3( e:Event ):void
    {
        // zoom3's position has been changed, update myOtherClip
        myOtherClip.x += zoom3.dragDiffX;
        myOtherClip.y += zoom3.dragDiffY;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.