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…
First couple of things that come to mind:
hsSlot1is not exactly top-left.hsSlot1as a direct child then it may be within another container that is positioned slightly off.Why not try this (within the object
hsSlot1itself):Dispatch an event from
hsSlot1when the mouse is “over” it:And listen for it from elsewhere:
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: