开发者

Restrict mouse move area in a flex application

开发者 https://www.devze.com 2023-03-02 02:41 出处:网络
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 t开发者_如何学Pythonhe cur

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 t开发者_如何学Pythonhe 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>


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号