如何在AS3中检测光标何时变为工字梁?

use*_*564 5 actionscript-3

我的flash项目中有一个自定义光标.默认情况下,当您将鼠标悬停在文本字段上时,自定义光标仍然可见,并且您可以同时看到工字形光标和自定义光标.为了避免这种情况,我需要在I光束光标出现时(即将鼠标悬停在文本字段上时)隐藏我的自定义光标.此外,光标始终设置为MouseCursor.AUTO状态.那么如何才能检测到它何时变为工字梁?提前致谢

Bar*_*klı 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
            }
        }
    }

}
Run Code Online (Sandbox Code Playgroud)