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

  • Home
  • SEARCH
  • 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 816309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:48:37+00:00 2026-05-15T01:48:37+00:00

i’m trying to trace the x and y coordinates from within a sprite. i’ve

  • 0

i’m trying to trace the x and y coordinates from within a sprite. i’ve added a rectangle to the stage:

var rect:Rectangle = new Rectangle(10, 10, 200, 200);
addChild(rect);
rect.x = rect.y = 100;

adding a Mouse_Move event to the rect, i can trace mouseX and mouseY to receive the coordinates of the stage while moving over the rect, but how do i get the local x and y coordinates? so if i mouse over the very top left of the rect sprite, the mouseX and mouseY return 10 as the global coordinates, but how do i make it return 0 and the local coordinates of the sprite?

i assumed localX and localY was what i was looking for, but this doesn’t work:

function mouseOverTraceCoords(evt:MouseEvent):void
{
trace(mouseX, mouseY, evt.localX, evt.localY);
}
  • 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-15T01:48:38+00:00Added an answer on May 15, 2026 at 1:48 am

    It depends how you have designed your Rectangle class,
    if you have done something like this:

    class Rect1 extends Sprite {
        public function Rect1(x:Number, y:Number, width:Number, height:Number) {
            var g:Graphics = graphics;
            g.beginFill(0xff0000, 0.5);
            g.drawRect(x, y, width, height);
            g.endFill();
        }
    }
    

    your local coordinate will be at 0,0 but you drawing start at x,y so when you are getting the localx, localY you will obtain x,y and not 0,0.

    But if your class is designed as something like that :

    class Rect2 extends Sprite {
        public function Rect2(x:Number, y:Number, width:Number, height:Number) {
            var g:Graphics = graphics;
            g.beginFill(0xff0000, 0.5);
            g.drawRect(0, 0, width, height);
            g.endFill();
    
            this.x = x;
            this.y = y;
        }
    }
    

    then your drawing start at 0,0 and your object is moved at x,y so the localX and localY from the MouseEvent will be ok.

    Edit:
    To get the local coordinate you can try using getBounds :

    function mouseOverTraceCoords(evt:MouseEvent):void {
     var dob:DisplayObject = DisplayObject(evt.target);
     var bnds:flash.geom.Rectangle = getBounds(dob.parent);
     var localX:Number=e.localX - bnds.x + dob.x;
     var localY:Number=e.localY - bnds.y + dob.y;
    
     trace(mouseX, mouseY, evt.localX, evt.localY, localX, localY);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
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

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.