Question: I have something really weird going on in my project (Flash CS5.5 and AIR 3...)

I need to check (for my own good reasons) whether the cursor is located within the bounds of a particular object. I'm using a simple code to do this...

```
if(mouseX > hsSlot1.x && mouseX < (hsSlot1.x + hsSlot1.width) && mouseY > hsSlot1.y && mouseY < (hsSlot1.y + hsSlot1.height))
    {
        //My code
    }

```

This, theoretically, should work perfectly! However, there is an offset (and one I did NOT set, mind you!) of about 16 between the hsSlot1's visual position (where it appears to start on the screen) and hsSlot1.x. There is a similar offset on the y axis, but I haven't measured it yet.

The only thing I can think of for this is that hsSlot1 is an instance of a button (one with only one state at that) that was scaled to fit. However, I don't think that is it, because the numbers show that the entire object is merely offset at its current size.

What the devil is going on?

EDIT: I found another way of doing this that wasn't working at first. However, an answer would still be appreciated, as this type of thing may be a problem later as well...

Answer: 
First couple of things that come to mind:

1. The registration point for the graphics for `hsSlot1` is not exactly top-left.
2. I can't tell what scope you're calling this code from, but if you're calling it from a container that doesn't contain `hsSlot1` as a direct child then it may be within another container that is positioned slightly off.

Why not try this (within the object `hsSlot1` itself):

Dispatch an event from `hsSlot1` when the mouse is "over" it:

```
if(mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height)
{
    dispatchEvent(
        new Event("CUSTOM_ROLLOVER")
    );
}

```

And listen for it from elsewhere:

```
hsSlot1.addEventListener("CUSTOM_ROLLOVER", _reaction);
function _reaction(e:Event):void
{
    trace('Glorious success.');
}

```

---

It still seems like you have graphics somewhere that aren't justified top-left to the registration point. This dodgy diagram I just drew up might help you understand what I mean and why it would affect your code the way it does:

![enter image description here](https://i.stack.imgur.com/XmItm.png)
The simple answer is that you're doing this the hard way, because an object's `x` and `y` and `width` and `height` properties don't necessarily correspond to its bounds. As Marty notes this is partly because an object's registration point (the origin of the object's local coordinate space) does not necessarily have to be at the object's corner. Further, depending on what you're doing scope-wise, the method you're using might need to account for whether the object is scaled, rotated, and so forth.

Solutions: 

1. The quick and easy way to do what you want is with [`DisplayObject.hitTestPoint()`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestPoint%28%29). That tells you whether a given (x,y) falls within the bounding box of your clip. Make sure to pass `false` for the third parameter if you just want to check against the object's bounding box. (Passing true will check the x,y against the object's actual shape.) To avoid scope issues, you specify the (x,y) in global coordinate space, so one easy way to test the mouse location is to do:

```
myObject.hitTestPoint( stage.mouseX, stage.mouseY, false)

```

Or you can of course transform local coordinates to global space before you compare.
2. The robust way to know everything about an object's bounds is to use [`DisplayObject.getBounds()`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#getBounds%28%29). Just be aware that you explicitly specify a scope to use for getBounds, so you need to have a clear idea of what scope you need to know about.