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