« ImageRail - Adding Click Event, Styles And HandCursor
» How To Make an Image With Border

ActionScript, How to, MXML

How To Set Focus on UIComponent

Stelian Crisan | 06.06.08 | 4 Comments

That is a  verry small isue, but some times we really need a fast answer.

I try to use setFocus method for diffrent UIComponents, for most of them it’s ok, but for a button for example you can’t see focus border using only setFocus method, so the solutions is to use also drawFocus method.

drawFocus method is called by the FocusManager when the component receives focus. The component should draw or hide a graphic that indicates that the component has focus. (recording flex help)

Please see this small example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" width="246" height="76">
    <mx:Script>
        <![CDATA[
            import mx.core.UIComponent;
            public function setFocusTo(object:UIComponent):void
            {
                object.setFocus(); 
            }
            public function drawFocusTo(object:UIComponent):void
            {
                object.setFocus();
                object.drawFocus(true);
            }
        ]]>
    </mx:Script>
    <mx:Button x="10" y="10" width="226" 
        label="my button" id="myButton" />
    <mx:Button x="10" y="42" 
        label="set focus" click="setFocusTo(myButton)"/>
    <mx:Button x="103" y="42" 
        label="set and draw focus" click="drawFocusTo(myButton)"/>
</mx:Application>
Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , , ,

This post was written by Stelian Crisan

Views: 3967

related

4 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

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

:

:


« ImageRail - Adding Click Event, Styles And HandCursor
» How To Make an Image With Border