How does focus works in Flex? -


i try figure out how focus mechanism work in flex. here comes example of mean:

let's assume have simple web application, contains custom component extends canvas , implements mx.managers.ifocusmanagercomponent. component overrides focusinhandler , focusouthandler methods , shows feedback on how called (thinner or thicker border). custom component contains text.

the source of component is:

<mx:canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="100" creationcomplete="cc();" implements="mx.managers.ifocusmanagercomponent"> <mx:script>     <![cdata[         import mx.containers.canvas;         import mx.controls.text;         import mx.controls.textarea;         import mx.core.uicomponent;         import mx.managers.ifocusmanagercomponent;          public function cc():void         {             text = new text;             text.text = "123";             addchild(text);              setstyle("backgroundcolor", "0xddddff");             setstyle("bordercolor", "0x000000");             setstyle("borderthickness", 1);             setstyle("borderstyle", "solid");         }          private var text:text;          override protected function focusinhandler(e:focusevent):void {             trace("focusinhandler, currfocus: " + focusmanager.getfocus());             setstyle("borderthickness", 4);         }          override protected function focusouthandler(e:focusevent):void {             trace("focusouthandler, currfocus: " + focusmanager.getfocus());             setstyle("borderthickness", 1);         }     ]]> </mx:script> </mx:canvas> 

here live version (with source view): http://rafalrybacki.com/lab/focus_question/. in app there textarea below canvas - ease focus manipulation when testing.

the questions:

  1. if click once on violet canvas receives focus (focusinhandler called), if click again focus lost (focusouthandler called) - why?

  2. of click on text canvas receives focus (focusinhandler called) , keeps when being clicked wherever on area (focusouthandler nevet called) - why?

maybe understanding of whole focus issue wrong? thank suggestions.

with respect,

rafal

hey rafalrybacki. [i'm in meeting, , can't spend time on question thought pointer or two:]

first, intent of canvas interact focusmanager differently component implements ifocusmanagercomponent. canvas implements ifocusmanagercontainer , while can accomplish you're trying accomplish making container ifocusmanagercomponent, i'd avoid it, because try think flex sdk team intended when using internal components.

what think they'd intend listen focusevent in container. focusevents bubble default, can accomplish need simple event listener.

note: listening focusout can confusing components have multiple uicomponents children --- i.e. combobox has uitextfield , button, component has multiple focusout , focusin events happening whithin same component. savior (i guess) doing container.contains() on focusmanger.getfocus() item (casting etc.) accurately set style.

i blab, if need beyond this, or know more why focusin or focusout evt being dispatched when being dispatched -- i'd happy slap code , explain why type of event being caught. best bet tho' (to fit within flex sdk guidelines) use event listener within container, , not fight component both ifocusmanagercomponent , ifocusmanagercontainer. messy.

hope helps. best of luck, jeremy


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -