• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting Cursor Position Programmatically

New Here ,
Oct 22, 2009 Oct 22, 2009

Copy link to clipboard

Copied

Hi,

In my app, the user clicks on an object, which centers the object on the screen. The user's cursor stays where he/she clicked. I find that it is kind of disorienting to have the object move without the cursor. For the user's convenience, I would like to move the cursor to the center of the stage as well.

Does anyone know how to do this?

Thanks!!

TOPICS
ActionScript

Views

5.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 22, 2009 Oct 22, 2009

Copy link to clipboard

Copied

hi,

This can't be done. AS3 provides a functionaity only to show/hide the mouse cursor. Anything else must be done with a movieclie and as3 code while the mouse cursor is hidden.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

Seriously? A Windows ActiveX control (like Flash Player) does have access to the cursor position and could move it around, I think the entire screen but definitely within its client area. I am sure other operating systems give installed plug ins this level of access. I wonder why Adobe doesnt provide us with access to it from action script... Oh well. I guess I will have to live with it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

But flash work also into MAC and Linux

There is Activexs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

Hey Suon, one of my most favorite things about flash is ,

the more inventive you are the things you can accomplish are 100%.

Let me see if i understand your problem correctly and i may have the solution for you.

what i beileve you were asking, is how to force a cursor to the placement of an item they clicked on as it moves towards the center of the stage? is that correct?

if so, then the following is how you can make this happen.

FIrst with the forementioned mouseHide, you remove the actual users mouse from the stage and replace it with another cursor (either a sprite/bitmap/movieClip).  Then as they move track their mouse position and include a counter variable which will act as an offset for the users cursor.  This is sort of like the zero on a scale.  when you place something on the scale you can zero out the value forcing the scale to say 0.

the idea is the same here.  as the user moves their mouse around, you will have the sprite acting as their cursor follow also always using the offset value which is currently set to 0.

var offsetY:Number=0

var offseX:Number=0

Once a user clicks on an object, as it moves to the screen, begin to increment the offsetX and offsetY forcing the cursor to match that of the object.  Now using these new offsetX and offsetY, as the user moves their mouse right, even though it might have been on the left margin of the window, you are forcing its x movement to be thatof their mouse position as wel as their offsetX.  this will allow you to make it appear as if the mouse is where it needs to be and fool the user about where thei rmouse truly is.  When you use mouseClick, you will have to verify if the points of the cursor are those of the points you need something ot be clickable, but again as i said earlier, the more imagination you have the more you can make happen happn.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

I did actually already think of that, but it messes up when the cursor leaves the Flash application. Suppose the user clicks on an object near the top edge of the application's client area. Then moves the fake offset cursor a little ways up. The user will see the mouse apparently still near the center of the screen, and then all of a sudden the mouse cursor will appear off the top of the application when the OS makes it appear once more and the fake offset cursor will stop responding. This would be much more disorienting for the user than not having the cursor warp to the center on a click.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

Gotcha,

ok so this one is being imaginitive but also knowing a good deal about the as3 api..

the methods you need to look into are MouseEvent.MOUSE_MOVE..  which will always track when a mouse movment is occuring in the player,.  Then

Event.MOUSE_LEAVE, which is when the mouse is no longer within the player.  at this point you can remove the mouse from the screen, or quickly have it tween to the edges to make it look less disorienting.

ALso another thing is Event.ACTIVATE, which is called every time that flash looses focus like browsing another window or if you hvae mac using expose.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

Yes , I suggested suOn696 to do this but he/she didn't anwered me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

I don't think that is the right solution. It will contradict a user's expectations far more than my original problem.

Original Problem: When the user clicks and the object moves to the center, since the user is going to interact further with that object immediately, the user has an expectation that the mouse will continue to be on the object they will interact with. But this is offset by the user's opposing expectation that the mouse will remain where they clicked. To me, the first expectation seems stronger than the second, which is why I would like to move the cursor, but in any case, it is a minor issue since both expectations are reasonable.

But the proposed solution raises a much more difficult problem. As I said in my response, the user could click on an object that is literally 1 pixel away from the application's top border. The real cursor would remain 1 pixel away, while the fake cursor would now be at the center of the screen. The user has an extremely powerful expectation that the mouse will act normaly when it is just moved around, since moving the mouse, though technically an event from the OS point of view, is not an event from the user's view, like clicking is. So they strongly expect continuity of motion.

If the user now moves the fake offet cursor a tiny bit up, even when animated as you suggest, the mouse will do something which the user is not expecting at all. It will look like the mouse just decided to leave the application for no reason. And for the duration of the tween there will be two cursors visible. All of this is a completely foreign experience to a user and contradicts the thousands of hours of expectation they have built up by normally moving cursors around screens. And the worst part is that they will never know when one of these strange events is going to occur, because they have no idea how it is being calculated.

Thanks for the input though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

The important thing is to make the UI realize the user's intentions. And having the mouse rush off the application, or disappear and show up off the side of the application while the user is just trying to move the mouse over something to interact with it in some way would be very annoying.

As far as I can tell, the only real solution is one where the real cursor position is moved, since this keeps the visuals perfectly aligned with the user's intent.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

As I say in my first post there is no way to change the x and y pos of mouse cursor with as3. The way to simulating this is by using a movie clip as cursor but in many cases this will get you into trouble. if the clip is animated this will rise the CPU usage. If it is not so important just use oginal cursor or handcursor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

What you are asking for is one of the worst design ideas. The point/mouse is an extension of the user's hand into the metaphor of the computer screen.

I expect my hand to be where I place it and where I move it not where some one else thinks it should go. No program at all should move the mouse pointer even one pixel unless the user moves the mouse. The problem with trying anticipate the user's intentions is that very few computers are smart enough to understand and adapt. Here is my story:

I used to teach various windows applications. Often in class we would be clicking something to open a dialog, change some setting, and then click accept. Some students would always have this problem where there window wouldn't open and I couldn't figure out why. It was because they had two things going against them. First they double clicked when they only needed to click once and second the stupid default was set to move the pointer to the default button. So their second click actually was on the accept button. In no way was this the user's intent and it really messed up a lot more people that you would think.

Additionaly I know a lot of folks who "loose" track of where there mouse is on the screen. And that is with it staying where they put it. I can't imagine if the mouse was always zooming off on its own.

Finally supposed your user selects the item and then gets a message that they have an IM or email or something and they want to switch to a different program. How are they to do that if the pointer keeps moving back to the center?

I just don't see how you can so clearly see that having the mouse rush off the application or show up somewhere strange is bad design, but that having YOUR application take over and rush the mouse here or there is a good idea. I'm guessing that you find it a good idea because it accomplishes something YOU want others to do, but trying to force people to do something is never a good idea. The annoyance that you would feel with the first is the same annoyance that a user would feel with the second. ugh! What ever you are designing is really a bad idea. Sorry to be so harsh.

The trick is to engineer it that they move the cursor back to the center. Or that they can work on the item in the place where they click on it or something like that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

LATEST

I hear what you are saying and this is exactly why I do not want to

implement a klugey solution and I agree that what you are saying is

almost always the case in most applications. But I do have a

counterexample for which moving the mouse cursor is intuitive. I just

happen to be working on exactly that sort of application. This is also

not my solution to the problem I am facing, but a common one for programs

of this nature. Here is the app: Consider a program whose background is

a large, complex map, like Google Maps (or various computer war games).

Generally, one must click on and drag the map to move it. This is the

nicest way to move the map as it retains a continuity of movement

between where the user expects the mouse to be and how the map is being

translated. Basically, it keeps continuity between the screen

coordinates, the map coordinates, AND the cursor coordinates. This is

really the best of all worlds.

But consider a feature on the map, some sort of object like a city, or a

tank, or a restaurant, etc. It has been a common design decision to

allow the user to double click on a feature like that and have the whole

map animate very quickly to bring the feature to the map's center. In

this case, the animation can disorient a user because the map

coordinates change rapidly with respect to the screen coordinates.

Google Maps does this without moving the cursor, and when you use it you

will feel torn between looking at the point that you double clicked on

as it animates to the center and zooms, and the cursor which stays where

you clicked. In amany computer games where maps contain distracting

animated sprites, this effect is much much stronger and the user is left

feeling disoriented.

Human vision works in a way that it is easiest for a person to orient

themselves once more by recognizing some sort of familiar landmark in

the new post-animation image. The key landmarks for the user to get

his/her bearing from in this case are the clicked-upon feature and the

cursor since this is the last thing the user concentrated on. But in the

post-animation image, these two features are no longer on top of each

other, so the vital piece of the new image looks different than before

and it is harder to recognize. Hence the torn feeling when double clicking on

Google Maps (try it, though their animation is slow so it is not as bad as it

could be).

It therefore makes sense to keep the two landmarks together

so that the user can more easily recognize what has just happened.

Hence, when the map animates quickly to move the feature to the center,

it would be nice to move the mouse there as well. This is a very

different example from the sort of applications you are talking about

since it already involves a very sudden perceptual shock, moving the

mouse is simply done to more easily get over the shock. This visual

disorientation only occurs when the background map is complex enough so

that it is somewhat hard for the human eye to really take all the

details in and make sense of them instantaneously. In my case, the map

is very complex and contains many animating objects, and I either have

to move the cursor with the center or I have to slow my animation down,

otherwise the app will induce uncomfortable visual confusion.

This is not a design decision which is unique to me, but numerous

experienced HCI people have come to the same design decision in many

computer games and GIS applications. This issue has been user tested

numerous times by numerous people. I think it is the optimal way to deal

with the issue because when looking at a map you are more interested in

the map coordinates than the screen coordinates, so keeping continuity

between the map coordinates and the cursor coordinates becomes more

important than keeping continuity between the screen coordinates and the

cursor coordinates. In this case, the user really is interested in

keeping the mouse cursor in the same place relative to the feature of interest

rather than the screen. This is especially true if the mapped feature is

interactive. Like in Google Maps, the double click is there explicitly to

bring attention to the object, i.e. move the object to the middle of the

screen and zoom in on it. The mouse must then be poised to effortlessly

click on the interactive features of the object. But like, I said, I

will have to live with Flash's limitations in the area and just slow the

animation down.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

You make a good point,

but on the other hand i would have to say that a user must also realize that when you interact with the scrren that things happen and there will be further things they willneed to do to continue with these steps.

If an object comes into the foreground of a selection being made.. the user realizes there is a transition state.  you are trying to get around this state, so the best thing you can attempt then is to help guide them to continue the way you see this.

how about this as an indea,

if a user clicks on someting to the left side of the screen, what if rather than that object zooming into the center you have it zoom in to where the mouse is.  then the user will be able to either continue using it where it is, or then give them the ability to move the item around.

or, use parallaxing so that by the time the user moves the mouse to the left to click on an object that object will have moved to the center because of the amount of pixels the mouse has moved left.  then when you click on it, by centering the image, they will alreayd be hovering on the item.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

But when you show again the mouse cursor it will on different place from the position of the custom mouse cursor. i.e. It  will "jump".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines