views:

203

answers:

2

Can I change mouse cursor for textfield to appear as a clickable object?

import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.text.*;
import flash.ui.ContextMenu;
import flash.utils.*;

import mx.core.*;
+1  A: 

I assume you want the cursor to be a hand, which is a default for clickable objects. Try the following AS code:

myTextField.buttonMode = true;
myTextField.useHandCursor = true;
myTextField.mouseChildren = false;

Or, in MXML:

<mx:Text buttonMode="true" useHandCursor="true" mouseChildren="false" />

See this article for an explanation.

Edit: This code uses the mx.controls.Text object. If you want it to work with flash.text.TextField objects, use the solution provided by davr.

Prutswonder
Access of possibly undefined property buttonMode through a reference with static type flash.text:TextField.
Tom
What type of container do you use that contains the text field?
Prutswonder
my class extends Sprite
Tom
Riiight, you're using a `flash.text.TextField` object, instead a `mx.controls.Text`. That explains a lot. Those objects don't support these properties. Any chance you could use a `flash.text.TextField` instead?
Prutswonder
is there another workaround such as making a invisible sprite around textfield?
Tom
If he's not using the Flex framework, I don't think he wants to import the framework just to get a hand cursor on a textfield.
davr
+2  A: 

You need to put the TextField inside a Sprite, sent the TextField's mouseEnabled to false, and the Sprite's buttonMode to true. For example:

var spr:Sprite = new Sprite();
var txt:TextField = new TextField();
txt.text = "Hello World!";
txt.mouseEnabled = false;
spr.buttonMode = true;
spr.addChild(txt);
addChild(spr);
davr
sorry, still a problem, my whole APP is a sprite, now this sprite does not appear at all?
Tom
Must be some other bug in your code. Can't really give any advice without seeing the entire code in question.
davr