Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash


Actionscript 3 :: Mouse - Local X And Y Coordinates Of Display Object?

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);
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);

View 3 Replies (Posted: May 27 10 at 10:16)

Sponsored Links:

Related Forum Messages For Flash category:
ActionScript 3 :: Inaccurate Mouse Coordinates Of Display Object?
When tracing the mouseX / mouseY or localX / localY coordinates of a display object, why does x start at 1 while y starts at 0? For example, I've drawn a simple 400 x 400 pixel sprite onto the stage with a MouseEvent.MOUSE_MOVE event listener that calls a handler function to trace the local coordinates of the mouse. The first, top-left pixel returns {x:1, y:0} and the last, bottom-right pixel returns {x:400, y:399}. Shouldn't both the x and y start and end with the same value? I'm not sure which makes more sense for a the first mouse coordinate (either 0 or 1) but it certainly doesn't make sense that they are different?

[SWF(width = "1000", height = "600", backgroundColor = "0xCCCCCC")]
import flash.display.Sprite;
var darkBlueRect:Sprite = createSprite();
darkBlueRect.x = 23;
[Code] .....

Posted: Jul 29 11 at 9:37

View 1 Replies!   View Related
Flex :: Display A Tooltip Only If The Mouse Cursor Is Within Certain Coordinates?
Within my component, I'm drawing some rectangles as below:


I need to display a custom tooltip for each rectange when the mouse cursor is hovering over it.

How can I do this? I'm using the MouseMove event to track when the cursor moves over these coordinates (that part is working), but when I change the tooltip text it's not refreshing

private function this_MOUSE_MOVE(event:MouseEvent):void


EDIT: The problem seems to be with the following line:


If I comment out the preceding line, it will display the new tooltip, but it will keep creating new ones and the old ones never get removed. But if I add that line, it doesn't add any tooltips! Is the code not being executed sequentially, i.e., is the code to remove the tooltip somehow getting executed after the code to add the tooltip?

Posted: Feb 24 11 at 6:35

View 1 Replies!   View Related
Actionscript 3 :: Convert Global Coordinates To Local Coordinates Of A UIComplenent In Flex Project?
I was trying to convert global coordinates to local coordinates of a UIComplenent in my flex project using below code using below code

var gp:Point = new Point(e.stageX,e.stageY); //global point
var lp:Point = uic.globalToLocal(gp); //local point

uic is UIComponent in which I have subclass of Sprite for drawing something I have set the sprite's mouseEnabled and mouseChildren to false to not interrupt the mouse event. above code is within uic's mousemove event where I was tracing the gp and lp gp was giving correct value and suprisingly lp was giving negetive values. when I move the move to the top left corner of uic i expect lp to be 0,0 but it is giving the -width of of uic. I broke my head for hours and ended up finding an alternate by using offsets. Infact my original code was much simpler like this which was same issue

var lp:Point = new Point(e.localX,e.localY);

I am not sure what exactly is causing this problem. the workaround had lot of issues and it creating a mess in my rest of the algorithms.Just now I found even more interesting thing (which is actually weird). for some reason I went and create a new lp2

var lp2:Point = new Point(e.localX,e.localY);

now surprisingly it was giving correct values as expected and I went back and changed the code as

var gp:Point = new Point(e.stageX,e.stageY); //global point
var lp:Point = uic.globalToLocal(gp); //local point
var lp2:Point = new Point(e.localX,e.localY);
var lp2:Point = uic.globalToLocal(gp);

now it is expected to have all the lp, lp2 and lp3 variables to be same but weiredly lp two is giving wrong value and lp2 and lp3 were giving correct. I am suspecting using the variable lp has something to do. I am not sure about that but above proves it so right now I am using lp2.

Posted: Dec 19 11 at 8:39

View 1 Replies!   View Related
ActionScript 2.0 :: Display Coordinates Of Object X And Y?
I have an object that moves when the arrows are pressed but how do i display the coordinates of the object, x and y? I tried


and then two dynamic boxes called x and y but it doesn't work!

Posted: February 17th, 2003

View 5 Replies!   View Related
Flash :: Finding Closest Object In Proxmity To Mouse Coordinates
i've been working on a problem for a while now, which involves targeting the closest movieClip in relation to the x y coords of the mouse, I've attached a nice little acompanying graphic.Each mc added to the stage has it's own sub-class (HotSpots) which uses Pythag to measure distance from mouse. At this stage i can determine the closest value from my Main class but can't figure out how to reference it back to the movieclip... hope this makes sense. Below are the two Classes.My Main Class which attachs the mcs, and monitors mouse movement and traces closest value.[code]

Posted: Mar 30 10 at 16:17

View 3 Replies!   View Related
Actionscript :: Get Local Symbol Coordinates From It?
I have a symbol originally created at [-100,-100] coordinate (left top corner). Now I put an instance of this symbol on a stage at [0,0] stage coordinates (by dragging it with a mouse in IDE). Having this instance can I still determine original [-100,-100] position from actionscript somehow? ([code]...

Posted: Aug 18 10 at 18:52

View 4 Replies!   View Related
Flex :: Rotate / Scale Display Object With Mouse
I am basically trying to create a display object transformation manager which will allow me to scale/rotate objects. I am currently trying to figure out how to rotate an object so its corner follows the current x and y of the mouse. I always get confused on the math of things like this. I know how to listen for the events and everything, I just am unsure of how to calculate the amount of rotation to apply. I will probably be rotating via a Matrix so I can rotate the object around its center, rather than the upper-left corner of it. My question here is: how do I get values when I don't want them constrained, like scaleX and scaleY?

Posted: Aug 5 10 at 22:42

View 1 Replies!   View Related
ActionScript 3.0 :: All Children In Display Object Firing Mouse Over?
I have a custom class extending MovieClip, and in my code I add a few children to this custom class.When I add my mouse over event listener, it works, but it fires every time the mouse rolls over any of the children too!I only want it to fire once when the display object as a whole is rolled over.

Posted: July 19th, 2010

View 1 Replies!   View Related
Actionscript 3.0 :: Matrix3d Local To Global Coordinates For Rotation?
I made a cube with as3. I wanted it to rotate in the Y Axis according to the horizontal mouse movement. It works nice when this is all I want. But if I try to also make it rotate on the X axis with the vertical mouse movement, things get screwy.

This happens because the transformations are added in the global coordinates, not the local ones. So, for Example, if I wanted the cube to rotate 30 degrees along its Y axis, I have to find a way to translate that into the global coordinates, and then apply that to the matrix3D of each face. I need a local to global translator.


Posted: Thu Feb 04, 2010 9:14 pm

View 1 Replies!   View Related
Actionscript 3 :: Get Unrotated Display Object Width/height Of A Rotated Display Object?
If I create a rectangle with 100px width and 100px height and then rotate it, the size of the element's "box" will have increased.With 45 rotation, the size becomes about 143x143 (from 100x100).Doing sometimes like cos(angleRad) * currentWidth seems to work for 45 rotation, but for other bigger angles it doesn't.At the moment I am doing this:

var currentRotation = object.rotation;
object.rotation = 0;
var normalizedWidth = object.width;


Posted: Jan 31 10 at 19:32

View 4 Replies!   View Related
Actionscript 2.0 :: Display Coordinates Of A Random Triangle In It?
I wanna generate a random triangle with coordinates, which shows the arcs of each corner in actionscript 2.0 with flash 8.0.

Posted: Apr 2 10 at 10:09

View 1 Replies!   View Related
Finding The Mouse X And Y Coordinates?
I'd like to use the x and y mouse coordinates as variables in a program. I'm very new to Flash and ActionScript and I'm not even sure which classes I need to import or which listeners or handlers I need to use.

Posted: 04-18-2011, 11:59 AM

View 1 Replies!   View Related
ActionScript 3.0 :: Mouse Coordinates In FF 3.6 On Mac OSX 10.6.3?
I have encountered really bad problem in one of our Flex projects. For some reason Flash can't get mouse coordinates properly. It returns something like (-107374182.4, -107374182.4) instead of good numbers. This happens when I'm using MOUSE_MOVE event in FF 3.6 on Mac OSX 10.6.3 with Flash Player 10. I have drag-n-drop in this projects, so with such ugly huge coords object goes far out of stage. Can't find solution in web, but there are some relative notes found...

For example, some info regarding 107374182.4 number can be found in internet.It seems 107374182.4 is something like NaN equivalent for some versions of Flash Player.Also I have found some notes regarding wrong mouse handling on Mac.The most interesting words there are: "on OSX it takes at least 1 frame to register the mouse's position". But it seems in my case it affects not only first frame after MOUSE_DOWN fired.Finally, there are movie on YouTube that demonstrates MOUSE_MOVE bug on FF/Mac.

I have tried:

- to get MouseEvent.stageX, MouseEvent.stageY (problem encountered);

- to get DisplayObject.root.mouseX, DisplayObject.root.mouseY (problem still appear, coordinates are bad);

- to use startDrag, stopDrag (it looks bugged too);

- to embed SWF into HTML with different wmode values.

Posted: 06-02-2010, 08:42 AM

View 0 Replies!   View Related
ActionScript 2.0 :: Mouse X And Y Coordinates?
I need to get the mouse x and y coords for a game I'm making. I know how to do it with fererence to another movie clip, button, textbox, ... but not to the stage.If all else fails, I will attach a movie clip at (0,0) and then get the x and y coords from there, but if there is a simpler way, I would like to do that.

Posted: May 8th, 2007

View 1 Replies!   View Related
ActionScript 2.0 :: [CS3] Rotating Using Mouse Coordinates
I'm trying to create a simple site that when you move the mouse to the right of the screen a movie clip rotates one way abt 45 degrees and moves the other way when the mouse moves to the left.

I'm trying to get the effect of a horizon line rotating to the mouses movement around the screen.

Posted: 03-12-2008, 09:21 AM

View 10 Replies!   View Related
ActionScript 3.0 :: Mouse Coordinates In An If Statement?
how to put mouse coordinates into an if statement, but as an 'if more than' but also 'if less than'. Something like:

if (mouseX > 190, but also <210) {
//do something

Is it possible to also do a similar thing to also include the Y position, to create a box of some sorts based on mouse position?
Something like:

if (mouseX > 190, but also < 210, mouseY > 20, but also < 100) {
//do something

I think it may have something to with setting each position as a var and pushing them into an array, but I can't get my head around it.

Posted: 09-29-2011, 03:41 PM

View 4 Replies!   View Related
IDE :: Longitude And Latitude Using Mouse Coordinates
I have a new project which requires getting the Longitude and Latitude coordinates on a world map. I have searched everywhere for either the code or a tutorial,

Posted: October 24th, 2003

View 4 Replies!   View Related
ActionScript 2.0 :: How To Move Mouse Over Coordinates
I am looking to create a menu similar to the one found here:All I need to know is how do you get the bar on this site the white rectangle) to go to a specific x-axis location on mouse over?

Posted: July 19th, 2004

View 3 Replies!   View Related
ActionScript 2.0 :: Mc Moving According On Mouse X And Y Coordinates?
trying to make a MC to change s x location according to the mouse position. Les say that the Mc moves to x=100 when the mouse_x is > 300 and y < 200. and moves back when the mouse goes back.

Posted: July 1st, 2004

View 9 Replies!   View Related
Flash :: Display The Coordinates Of A Random Triangle In A Graph Which Ranges From +10 To -10 XY Axis?
how i display the coordinates of a random triangle in a graph which ranges from -10 to +10 in XY axis with the points like A(2,1) etc with arcs in each corner, in actionscript 2.0

Posted: Apr 3 10 at 18:45

View 1 Replies!   View Related
Put X And Y Coordinates Of Mouse In Two Variables But Only On A Click On Workspace?
How can I put the X and Y coordinates of the mouse in two variables, but only on a click on the workspace.

Posted: 04-06-2009, 03:56 AM

View 1 Replies!   View Related
Professional :: Control Timleline With Mouse X Coordinates
how to create a movie with a sequence of pictures and controlling the timeline frames with mouse x-coordinates?

Posted: Feb 1, 2010 1:22 AM

View 4 Replies!   View Related
Professional :: Control Frames With Mouse X Coordinates?
I want to take a folder with 20 pictures, in some way convert them into a movie. And then apply so that I can navigate the frames one by one in the movieclip by moving the mouse right and left (move mouse left - navigate backwards frame by frame, move mouse right - navigate forward frame by frame).

Posted: Feb 1, 2010 5:16 AM

View 2 Replies!   View Related
Flex :: Obtain Item For Mouse X/y Coordinates?
my mission is to select an item in a DataGrid instance with nothing but the coordinates on screen.

We are implementing right-click functionality in our Flash application, with the goal of being able to right-click a DG row, which would select that row plus show a popup window containing some context commands.

I have managed to get the right click event into my Flex app with the help of this site.

Further progress so far has been to obtain the DataGrid instance via

var objects : Array = this.getObjectsUnderPoint(new Point(this.mouseX, this.mouseY));

and then to investige each of the array's items, for one of those 'parent.parentList' refers to the DataGrid instance.

I couldn't find any point-to-item converter function or anything.

PS: Using the standard Flash ContextMenu is, unfortunately, not an option.

Posted: Nov 24 09 at 13:00

View 3 Replies!   View Related
Copyright 2005-08, All rights reserved