- Added setFocuable().
- createField calls it. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@725 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -91,6 +91,9 @@ public class TextFieldUtil
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a TextField.
|
* Create a TextField.
|
||||||
|
* The field will have setFocusable() called on it.
|
||||||
|
* Note that if the autoSize property is not none, then the field will be resized
|
||||||
|
* to the size of the text, overwriting any width/height properties specified.
|
||||||
*
|
*
|
||||||
* @param initProps contains properties with which to initialize the TextField.
|
* @param initProps contains properties with which to initialize the TextField.
|
||||||
* Additionally it may contain the following properties:
|
* Additionally it may contain the following properties:
|
||||||
@@ -112,6 +115,7 @@ public class TextFieldUtil
|
|||||||
tf.defaultTextFormat = createFormat(formatProps);
|
tf.defaultTextFormat = createFormat(formatProps);
|
||||||
}
|
}
|
||||||
updateText(tf, text);
|
updateText(tf, text);
|
||||||
|
setFocusable(tf);
|
||||||
|
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
@@ -152,6 +156,15 @@ public class TextFieldUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a special MouseEvent.CLICK listener so that the specified field is focusable
|
||||||
|
* even inside a security boundary.
|
||||||
|
*/
|
||||||
|
public static function setFocusable (field :TextField) :void
|
||||||
|
{
|
||||||
|
field.addEventListener(MouseEvent.CLICK, handleFieldFocus);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include the specified TextField in a set of TextFields in which only
|
* Include the specified TextField in a set of TextFields in which only
|
||||||
* one may have a selection at a time.
|
* one may have a selection at a time.
|
||||||
@@ -208,6 +221,28 @@ public class TextFieldUtil
|
|||||||
_lastSelected = null;
|
_lastSelected = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle focusing the text field.
|
||||||
|
*/
|
||||||
|
protected static function handleFieldFocus (event :MouseEvent) :void
|
||||||
|
{
|
||||||
|
var tf :TextField = TextField(event.currentTarget);
|
||||||
|
if (tf.stage.focus == tf) {
|
||||||
|
return; // already has focus, bail.
|
||||||
|
}
|
||||||
|
|
||||||
|
// else, assign focus
|
||||||
|
tf.stage.focus = tf;
|
||||||
|
|
||||||
|
// try to be smart and move the cursor near the click
|
||||||
|
if (tf.selectable) {
|
||||||
|
var idx :int = tf.getCharIndexAtPoint(event.localX, event.localY);
|
||||||
|
if (idx != -1) {
|
||||||
|
tf.setSelection(idx, idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The last tracked TextField to be selected. */
|
/** The last tracked TextField to be selected. */
|
||||||
protected static var _lastSelected :TextField;
|
protected static var _lastSelected :TextField;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user