actionscript 3 - set focus in button when open popup in flex -
i'm having problem set focus on button open popup. button gets focus, not appearance focu. if no component focu.
my source code:
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600"> <fx:script> <![cdata[ import comps.mypopupwindow; import mx.events.flexevent; import mx.managers.popupmanager; // declare variable reusable custom popup window private var popup:mypopupwindow; private function openpopupwindow(evt:flexevent=null):void { // open popup window modal popup window // , store in variable later use popup = popupmanager.createpopup(this,mypopupwindow,true) mypopupwindow; } protected function button1_clickhandler(event:mouseevent):void { openpopupwindow(); } ]]> </fx:script> <s:button click="button1_clickhandler(event)" label="open popup"/> </s:application> the popup:
<mx:titlewindow xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" layout="vertical" title="title" showclosebutton="true" keydown="titlewindow1_keydownhandler(event)" close="titlewindow1_closehandler(event)" creationcomplete="titlewindow1_creationcompletehandler(event)"> <fx:script> <![cdata[ import mx.controls.alert; import mx.core.iflexdisplayobject; import mx.events.closeevent; import mx.events.flexevent; import mx.managers.ifocusmanagercomponent; import mx.managers.popupmanager; protected function titlewindow1_creationcompletehandler(event:flexevent):void { login.setfocus(); var componente:button = focusmanager.getfocus() button; //alert.show(componente.name ,'save'); ensure component holds focu. } protected function titlewindow1_keydownhandler(event:keyboardevent):void { if (event.charcode == keyboard.escape) { this.dispatchevent(new closeevent(closeevent.close)); } } protected function titlewindow1_closehandler(event:closeevent):void { popupmanager.removepopup(event.target iflexdisplayobject); } protected function save_keydownhandler(event:keyboardevent):void { if (event.keycode == keyboard.enter) alert.show('login','login'); } protected function login_clickhandler(event:mouseevent):void { alert.show('login','login'); } ]]> </fx:script> <mx:button id="login" label="login" click="login_clickhandler(event)"/> <mx:button id="cancel" label="cancel" /> </mx:titlewindow> thanks.
better manually dispatch event on particular button. http://help.adobe.com/en_us/flex/4.0/usingsdk/ws2db454920e96a9e51e63e3d11c0bf69084-7ce1.html
Comments
Post a Comment