Using embedded fonts with tool tips in Flex

by Peter deHaan on March 26, 2008

in ToolTip, ToolTipEvent

The following example shows how you can use an embedded font with an error tool tip in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/26/using-embedded-fonts-with-tool-tips-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Style>
        @font-face {
            src: local("Comic Sans MS");
            fontWeight: normal;
            fontFamily: ComicSansMSEmbedded;
        }

        .errorTip {
            borderStyle: "errorTipAbove";
            fontFamily: "ComicSansMSEmbedded";
            fontSize: 12;
            fontWeight: normal;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.events.ToolTipEvent;
            import mx.controls.ToolTip;

            private function init():void {
                ToolTip.maxWidth = textInput.width;
            }

            private function textInput_toolTipShown(evt:ToolTipEvent):void {
                var tt:ToolTip = evt.toolTip as ToolTip;
                tt.x = textInput.x;
                tt.y = (textInput.y - tt.height);
                tt.rotation = 5;
            }
        ]]>
    </mx:Script>

    <mx:TextInput id="textInput" text="{new Date().toDateString()}"
            errorString="The quick brown fox jumped over the lazy dog"
            toolTipShown="textInput_toolTipShown(event);" />

</mx:Application>

View source is enabled in the following example.

{ 5 comments… read them below or add one }

1 prasad March 28, 2008 at 5:58 am

Hi,
gr8 work!

Is this tool tip created in Flex 2.0 or higher version ?

Regards
Prasad

Reply

2 peterd March 28, 2008 at 6:53 am

prasad,

I only tested this in Flex 3.

Peter

Reply

3 Boris September 9, 2008 at 5:40 am

Is it possible to draw the errorTip without rounded-corners? Do you have any ideas??

atb Boris

Reply

4 peterd September 9, 2008 at 7:59 am

Boris,

I haven’t tried it, but I think you may need to extend the mx.skins.halo.ToolTipBorder class, override the updateDisplayList() method, and specify the corner radius in the drawRoundRect() method for the “errorTipRight”, “errorTipAbove”, and “errorTipBelow” skin states.

Peter

Reply

5 Boris September 10, 2008 at 12:42 am

Thanks Peter, it’s really incredible how many hours of lifetime i’ll saved with the help of your blog – THANK YOU

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: