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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:39:45+00:00 2026-06-17T08:39:45+00:00

Thank you for taking the time to answer my question. So the problem is

  • 0

Thank you for taking the time to answer my question. So the problem is making a simple rectangle follow my mouse. I really don’t understand why this code isn’t working.
package Classes

{
    import flash.display.MovieClip;
    import flash.display.Stage;

    import flash.events.Event;


    public class watever extends MovieClip
    {
        var stageRef:Stage;

        public function watever(x:Number, y:Number, stageRef:Stage)
        {
            this.x = x;
            this.y = y;
            this.stageRef = stageRef;
            addEventListener(Event.ENTER_FRAME, moveMe, false, 0, true);

        }


        public function moveMe(e:Event):void
        {
            this.x = mouseX;
            this.y = mouseY;

            trace(mouseX);
        }
    }
}

The object just goes on “strange” places, so I tried to trace mouseX and I got silly numbers in the output

-1373
1790
-1373
1790
-1373
1790
-1373
1790
-1373
1790
-1373
1790
-1373

However, if I declare it from the parent class it works fine. What’s wrong with the code, please?
(Below is how it works from the parent class)

public function DocumentClass()
        {


            c = new watever(200, 200, stage)
            stage.addChild(c);
            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

        }
        private function loop(e:Event):void
        {
            c.x = mouseX;
            c.y = mouseY;
        }
  • 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-06-17T08:39:46+00:00Added an answer on June 17, 2026 at 8:39 am

    The mouse position is relative to the DisplayObject (mouseX is the same as this.mouseX if that makes it clearer), so if your watever MovieClip is at (0, 50) on the stage, and the mouse is at (0, 60), watever.mouseY will be 10.

    When you read it from the document class, you’re getting mouseX and mouseY relative to the stage, which is why it works correctly. You can just change moveMe() to do this:

    public function moveMe(e:Event):void
    {
        this.x = stageRef.mouseX;
        this.y = stageRef.mouseY;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thank you for looking at and taking time to answer my question! I would
thank you for taking the time and interest reading this and hopefully helping me
Thanks for taking the time to answer my question. I want to check if
Hi and thanks for taking the time to answer my question. After a year
Hi and thanks for taking the time to answer my question. I have an
Hi and thanks for taking the time to answer my question. Appreciate it. Let's
Thanks for taking time to review this question. I've been trying to fix a
thank you for taking your time to read this message. I hope you are
Hi and thanks for taking the time to answer my question. I have a
First off good day and thanks for taking the time to answer my question.

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.