tags:

views:

877

answers:

3

How to add mnemonic character to a regular button in Flex? Show me some examples.

+1  A: 

http://livedocs.adobe.com/flex/3/html/help.html?content=accessible_7.html

Peter Miehle
Sorry, I don't understand. How is it related to mnemonic shortcuts?
HappyCoder
+2  A: 
Shashi Bhushan
+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
Great! :-) Thanks a lot.One thing, "if (shortcutPosition == 0)" case should be also considered.
HappyCoder