简体   繁体   中英

How to trap mouse cursor in Flex/Flash?

I'm working on an interface control that allows users to navigate a 3d space with their mouse. Currently we are using up/down/left/right arrow buttons, but what I'd really like to switch to is a clickwheel type interface.

The interaction I'm looking for is:

  1. User clicks "Up" section of click wheel.
  2. Mouse cursor disappears.
  3. User drags mouse up to quickly move forward through location
  4. User drags mouse down to quickly move backward through location
  5. User releases mouse button and cursor reappears, still inside click wheel

The problem I see with this is that the invisible mouse will quickly move out of the movie and stop tracking. Has anybody dealt with this before? I'm sure I saw a flash toy somewhere that trapped the mouse inside a box, but can't find it now. :(

It's impossible to 'trap' the mouse cursor. The best you can do is hide the cursor (or not) and just increase the ratio between mouse movement and whatever you're trying to do.

Like others have said, you can't trap the mouse (the web would be an awful place if arbitrary web code could do this), but you can detect when the mouse has exited the swf and perform logic to handle this occurance by listening for Event.MOUSE_LEAVE. Perhaps you can interpret this event as though it were a mouse_up event?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM