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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:30:41+00:00 2026-05-25T17:30:41+00:00

I’m trying to make a simple function to select and drag a MovieClip, without

  • 0

I’m trying to make a simple function to select and drag a MovieClip, without using the startDrag() function.

I have a few MCs on the stage, when mouse down on a MC, I want the MC to move with the mouse. But when I hold the mouse down, the MC starts to “tremble” and I’m not sure why.

I have the code inside each MC for other reasons. Here is what I have so far:

var selectX:Number; //x coordinate of mouse click (to select right point on mc on mouse down)


this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

function mouseDownHandler(e:MouseEvent):void {  
    selectX = this.x - mouseX;
    addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}


function mouseUpHandler(e:MouseEvent):void {
    mouseX2 = mouseX;
    removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}

function onEnterFrameHandler(e:Event):void {
    this.x = mouseX + selectX + stage.x;
}
  • 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-25T17:30:42+00:00Added an answer on May 25, 2026 at 5:30 pm

    This is happening because you are using mouseX of the inside of the movieclip. but when you are trying to set the x of the movieClip it sets the x on the parent movieclip.

    e.g.:

    mainClip
    |– DragableButton

    when you adding DragableButton.x = 100, it is x position insided of the mainClip.
    and when your code is taking mouseX inside of the DragableButton, the real mouseX = x + mouseX. and since mouseX inside of the DragableButton is equals e.g. 20, and you adding: selectX = this.x - mouseX -> if you have selectX = 100 – 20. but not 100 – 120 as it should be.

    so if you still want to keep to your code change it a bit:

    var selectX:Number; //x coordinate of mouse click (to select right point on mc on mouse down)
    var mouseX2:Number;
    
    
    this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    
    function mouseDownHandler(e:MouseEvent):void {  
        selectX = this.x - parent.mouseX;
        // selectX = this.x - stage.mouseX;
        addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
    }
    
    
    function mouseUpHandler(e:MouseEvent):void {
        mouseX2 = parent.mouseX;
        removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
    }
    
    function onEnterFrameHandler(e:Event):void {
        this.x = parent.mouseX + selectX;
        // this.x = stage.mouseX + selectX;
    }
    

    p.s. stage.x = 0, it will be always. unless you change the property.
    p.s.s. stage is only one and same instance no matter from which MC you are trying to get it.

    my suggestion draging would be:

    this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    
    function mouseDownHandler(e:MouseEvent):void
    { 
        this.startDrag();
        stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    }
    
    
    function mouseUpHandler(e:MouseEvent):void
    {
        this.stopDrag();
        stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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

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.