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
Here is something that tries to mimic what you want, it adds a single event listener to the stage and detects if roll over/out events happen on text fields and changes the cursor accordinly :
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
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With