5

I have a custom cursor in my flash project. By default the custom cursor remains visible when you hover over a textfield and you get the I-beam cursor and your custom cursor visible at the same time. To avoid this I need to hide my custom cursor whenever the I-beam cursor appears (i.e. when you hover the mouse over a textfield). Also the cursor is always set to MouseCursor.AUTO state. So how can I detect when it changes to I-beam? Thanks in advance

4

1 回答 1

1

这是试图模仿您想要的东西,它向舞台添加了一个事件侦听器,并检测是否在文本字段上发生翻转/滚动事件并相应地更改光标:

package 
{
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.ui.Mouse;
    import flash.ui.MouseCursor;

    public class Main extends Sprite 
    {

        private var textField1:TextField = new TextField();
        private var textField2:TextField = new TextField();

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point

            var loader:Loader = new Loader();
            loader.load(new URLRequest('bg.png'));
            addChild(loader);               

            textField1.text = "Text Field 1";
            textField1.border = true;
            textField1.x = 100;
            addChild(textField1);

            textField2.text = "Text Field 2";
            textField2.border = true;
            textField1.x = 400;
            addChild(textField2);

            Mouse.cursor = MouseCursor.HAND;

            stage.addEventListener(MouseEvent.ROLL_OVER, onRollOver, true);
            stage.addEventListener(MouseEvent.ROLL_OUT, onRollOut, true);
        }

        private function onRollOver(e:MouseEvent):void 
        {
            var tf:TextField = e.target as TextField;
            if (tf)
            {
                Mouse.cursor = MouseCursor.IBEAM;
                //hide your custom cursor here
            }
        }

        private function onRollOut(e:MouseEvent):void 
        {
            var tf:TextField = e.target as TextField;
            if (tf)
            {
                Mouse.cursor = MouseCursor.HAND;
                //show your custom cursor here
            }
        }
    }

}
于 2013-03-03T23:23:03.987 回答