How do I add a mnemonic symbol to a regular button in Flex? (This is needed for shortcuts)

How do I add a mnemonic symbol to a regular button in Flex? Show me some examples.

+1


a source to share


3 answers


Here's an advanced button component to help you get the job done:

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 the "~" character in front of the character you want to underline to indicate it as a mnemonic character.



Example (you need to add xmlns:test="test.*"

to container component):

<test:ShortcutButton label="~Update" />

      

+2


a source


First solution:

<? xml version = "1.0" encoding = "ISO-8859-1">

<mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml">

Just set the encoding value of the mxml file and you can enter the special character on the right. The ISO-8859-1 encoding type works for me with the © character.

Second solution:

For example, the © escape sequence is only defined for HTML, not XML. According to the W3C XML 1.0 recommendation, only a few such mnemonic escape sequences are defined. However, you can include other characters by using numeric symbolic links by specifying their Unicode Code Points.



See: http://www.w3.org/TR/REC-xml/#syntax

For example, a copyright symbol can be expressed as (without double quotes): "©" or "& xA9;" (hexadecimal). This will work if the font you are using has glyphs for the code point you are referring to (since Unicode defines characters and symbols from a very wide range of languages, many of which will not exist in all fonts.

For a list of all Unicode characters and their code points, you can refer to the Unicode Chart Codes available here:

http://www.unicode.org/charts/

You can also list online by specifying codes for some of the more common characters and most operating systems now have a character or character collector (such as the Microsoft Windows Character Symbol Utility) that will often list character code points as well.

+2


a source


+1


a source







All Articles