How to add mnemonic character to a regular button in Flex? Show me some examples.
views:
877answers:
3Sorry, I don't understand. How is it related to mnemonic shortcuts?
HappyCoder
2009-05-25 15:07:02
+1
A:
Here is an extended button component, that can help you deal with the task:
package test
{
import mx.controls.Button;
import flash.text.TextFormat;
public class ShortcutButton extends Button
{
private static const underlineTF:TextFormat = new TextFormat(null, null, null, null, null, true);
public function ShortcutButton()
{
super();
}
protected var shortcutPosition:int = -1;
override public function set label(value:String):void
{
shortcutPosition = value.indexOf("~");
if (shortcutPosition >= 0)
value = value.substring(0, shortcutPosition) + value.substring(shortcutPosition + 1);
super.label = value;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (shortcutPosition > -1 && shortcutPosition < textField.text.length - 1)
textField.setTextFormat(underlineTF, shortcutPosition, shortcutPosition+1);
}
}
}
Just place "~" symbol before the symbol you want to underline to show it's a shortcut mnemonic character.
Example (you'll have to add xmlns:test="test.*"
to the container component):
<test:ShortcutButton label="~Update" />
Hrundik
2009-06-07 19:13:46
Great! :-) Thanks a lot.One thing, "if (shortcutPosition == 0)" case should be also considered.
HappyCoder
2009-06-09 18:16:17