0

In my flex application I need to restrict the mouse from moving in a certain area.In other words I want to create a 'No Entry Zone' for the mouse in the application.Hiding the cursor when mouse enters the area is not a solution for me.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">

    <mx:Script>
        <![CDATA[
            protected function canvas2_mouseMoveHandler(event:MouseEvent):void
            {
                trace('mouse moved inside');//this trace should not be executed.
            }

        ]]>
    </mx:Script>

    <mx:Canvas x="250" y="180" backgroundColor="white" height="300" width="400" mouseMove="canvas2_mouseMoveHandler(event)">
        <mx:Text text="Mouse Entry not allowed"/>
    </mx:Canvas>
</mx:Application>
user700284
  • 13,540
  • 8
  • 40
  • 74

2 Answers2

1

You cannot programatically position (so neither fix) the mouse cursor in Flex (as pointed out by Alex Harui in this answer).

Although, you could give a try to this approach.
By tracking the mouse's x|y you could

  1. draw the cursor at its last enabled position when entering your restricted canvas (+ hide it), and
  2. remove the drawn cursor on mouseOut event (+ show the cursor).

For restricting the drag / drop in your Canvas you just set the dragEnter property (event handler) on it:

dragEnter="event.stopImmediatePropagation();"

You can see some samples of enabling and disabling drag/drop operations here

rekaszeru
  • 19,130
  • 7
  • 59
  • 73
  • Hiding the mouse pointer is not going to work,because it is the movement of cursor that I want to restrict.Basically,I wanted to restrict the drag and drop to a specific area(http://stackoverflow.com/q/5713140/700284). So,I thought if I could somehow restrict the mouse cursor movement and stall cursor at where it is,I would achieve it.So it is not going to be possible to do it the way I want right? BTW:Second link you posted seems to be pointing to the wrong url – user700284 May 03 '11 at 12:17
  • For restricting drag and drop on a flex component you need to specify the proper handlers. Please see my update. (sorry about the wrong link, i've updated it too). – rekaszeru May 03 '11 at 12:32
0

We can not control/set Mouse position From Flex/ActionScript

but we can make Canvas Mouse in-sense-able applying properties

i.e. when we move mouse over it would not fires an event. properties are

mouseChildren="false"
mouseEnabled="false"

Hopes that helps

Imran
  • 2,906
  • 1
  • 19
  • 20
  • I want to give a visual feedback to the user that mouse cannot enter that area.That is,mouse can move only till the boundaries of the area and if user tries to take the mouse inside,mouse movement should be restricted.We cannot control that? – user700284 May 03 '11 at 12:03
  • From AS3/Flex my ans is NO, but you can use wrapper to control mouse position like ASP.net in that case you need to call ASP.net/JS method From Flex when Mouse moves in restricted Area but never try this, – Imran May 03 '11 at 12:13
  • By your Drag-Drop comment i found that you dont want to restrict mouse but an object see Flash Example http://www.flashandmath.com/basic/dragdroptour/dd_tour1.html is that what you required? – Imran May 03 '11 at 12:50