We love choice

Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://fxr.groups.adobe.com.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, How to, MXML

How To Set Focus on UIComponent

Stelian Crisan | 06.06.08 | 6 Comments

Google Buzz

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:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , , ,

This post was written by Stelian Crisan

Views: 36014

related

6 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="" escaped="">

:

:


«
»