Flex文本输入焦点

时间:2011-08-09 12:49:47

标签: flex actionscript-3 air

在我的Air应用程序中,我有两个焦点问题。 实际上,当我尝试使用tab键移动到我的表单内部时,顺序并不好。 第二点,即使光标位于文本输入中,焦点边框也不可见。

查找以下部分代码

使用Tab键移动

this.focusManager.activate();
this.focusManager.setFocus(this.fdNom);

我的TextInput CSS

 s|TextInput 
{
    focusColor: #33CC00;
    color : #343434;
    font-weight : normal;
    font-family: Helvetica ;
    font-size : 12;

}

我的表格

<s:Form x="0" y="94" id="foPerso" width="100%" height="100%" 
            includeInLayout="true" includeIn="tb1" 
            backgroundColor="#FFFFF">

        <s:layout>
            <s:FormLayout gap="3" paddingLeft="0"/> 

        </s:layout>



        <s:HGroup width="100%" gap="3" horizontalAlign="left" resizeMode="noScale"
                  verticalAlign="baseline" >


            <s:DropDownList id="cbQualite" dataProvider="{DP_PAT_CIVIL}"
                            selectedItem="{getSelectedItem(DP_PAT_CIVIL, objectPatient.paQualPatient)}" 
                            change="objectPatient.paQualPatient = event.currentTarget.selectedItem.label"/>

            <s:FormItem label="Nom" >
                <s:TextInput id="fdNom" width="200" 
                             text="@{objectPatient.paNomU}"

                             />
            </s:FormItem>
            <s:FormItem  label="Prénom" >
                <s:TextInput id="fdPrenom" width="200" text="@{objectPatient.paPrenom}"/>
            </s:FormItem>
            <s:DropDownList id="cbDossier1" dataProvider="{DP_PAT_DOS1}" width="118" height="22" tabIndex="3"
                            change="objectPatient.paQualPatient = event.currentTarget.selectedItem.label"
                            />

            <s:FormItem label="" >
                <s:TextInput id="fDossier1" width="90" paddingRight="5" text="@{objectPatient.paDossier1}"/>
            </s:FormItem>
        </s:HGroup>

我的表单是自定义的TitleWindow组件。

感谢您的帮助

4 个答案:

答案 0 :(得分:3)

使用TextInput tabindex属性来操作taborder。

答案 1 :(得分:0)

(1)我可能只是允许Flex处理Tab键,而不是自己管理它。

(2)您是否正在为没有焦点皮肤的TextInput使用自定义皮肤?

答案 2 :(得分:0)

Flex将根据MXML中添加组件的顺序自动为您设置Tab键顺序。如果您的MXML如下所示:

<?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="200" minHeight="200">

  <s:TextInput id="textInput1" 
               x="0" y="0" 
               text="TEXT INPUT #1" />
  <s:ComboBox id="comboBox2" 
              x="0" y="60">
    <s:dataProvider>
      <mx:ArrayList>
        <fx:String>Red</fx:String>
        <fx:String>Orange</fx:String>
        <fx:String>Yellow</fx:String>
        <fx:String>Blue</fx:String>
        <fx:String>Green</fx:String>
      </mx:ArrayList>
    </s:dataProvider>
  </s:ComboBox>
  <s:TextInput id="textInput2" 
               x="0" y="30"
               text="TEXT INPUT #2" />
</s:Application>

当您点击标签按钮在字段之间移动时,它会转到TextInput1,然后是Combobox1,然后转到TextInput2,即使它们按照x的不同顺序排列{1}},y坐标。这是由于这些组件出现在MXML中的顺序。设置tabIndex属性时,您可以手动控制Tab键顺序。

<?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="200" minHeight="200">

  <s:TextInput id="textInput1" 
               x="0" y="0" 
               text="TEXT INPUT #1"
               tabIndex="1"/>
  <s:ComboBox id="comboBox2" 
              x="0" y="60"
              tabIndex="3">
    <s:dataProvider>
      <mx:ArrayList>
        <fx:String>Red</fx:String>
        <fx:String>Orange</fx:String>
        <fx:String>Yellow</fx:String>
        <fx:String>Blue</fx:String>
        <fx:String>Green</fx:String>
      </mx:ArrayList>
    </s:dataProvider>
  </s:ComboBox>
  <s:TextInput id="textInput2" 
               x="0" y="30"
               text="TEXT INPUT #2"
               tabIndex="2"/>
</s:Application>

对于焦点边框,除非您在组件上设置自定义外观,否则它们仍应具有默认的蓝色焦点边框。 Combobox组件也可以获得焦点没问题。确保您没有将tabFocusEnabled属性设置为false

答案 3 :(得分:0)

我找到了解决方案的一部分,但我需要你帮忙完成。

事实上,使用Spark Window一切都运行良好,但我创建了这样的窗口,并且焦点不可见。怎么了?

var wdetcorr:wDetailCorrespondant = new wDetailCorrespondant();
            wdetcorr.monIdCorresp = correspDG.selectedItem.crIndex;

            var wOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
            wOptions.systemChrome = NativeWindowSystemChrome.NONE;
            wOptions.transparent = false;
            var fnwDetailPatient:FlexNativeWindow = new FlexNativeWindow(wdetcorr, wOptions);
            fnwDetailPatient.activate();

FlexNativeWindow代码是:

package fr.ui.windowSkin
{
import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

import mx.core.IUIComponent;
import mx.core.IVisualElement;
import mx.core.IVisualElementContainer;
import mx.core.UIComponent;
import mx.events.*;
import mx.managers.WindowedSystemManager;

[Event(name="creationComplete", type="mx.events.FlexEvent")]

public class FlexNativeWindow extends NativeWindow implements IFlexNativeWindow
{
    private var _systemManager:WindowedSystemManager;

    private var _content:UIComponent;

    private var _window:IVisualElementContainer;

    public function FlexNativeWindow(window:IVisualElementContainer, initOptions:NativeWindowInitOptions = null)
    {
        super(initOptions);


        _window = window;

        addEventListener(Event.ACTIVATE, windowActivateHandler);

    }

    public function addElement(control:IVisualElement):void
    {
        _window.addElement(control);
    }

    public function removeElement(control:IVisualElement):void
    {
        _window.removeElement(control);
    }

    private function windowActivateHandler(event:Event):void
    {
        event.preventDefault();
        event.stopImmediatePropagation();
        removeEventListener(Event.ACTIVATE, windowActivateHandler);

        if (stage)
        {
            if (!_systemManager)
                _systemManager = new WindowedSystemManager(IUIComponent(_window));

            stage.addChild(_systemManager);

            dispatchEvent(new FlexEvent(FlexEvent.CREATION_COMPLETE));

            stage.addEventListener(Event.RESIZE, windowResizeHandler);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);

        }
    }

    private function keyDownListener (e:KeyboardEvent):void {

        if (e.keyCode == Keyboard.ESCAPE) {
            stage.nativeWindow.dispatchEvent(new Event("myEventClose", true));
            stage.nativeWindow.close();
        }


    }

    private function windowResizeHandler(event:Event):void
    {
        // prise en compte de la valeur mini
        UIComponent(_window).height = stage.stageHeight;
        UIComponent(_window).width = stage.stageWidth;


    }
}

}