2012-04-07 51 views
0

我正在爲類的數據提供程序應用程序,並希望進一步的可用性和添加Tab鍵導航,但下面的tabIndex代碼沒有做任何事情。我想要在按鈕和文本框之間進行選擇。 Tab鍵與數據提供者一起工作嗎?使用Tab鍵as3

package 
{ 

    import fl.controls.Button; 
    import fl.controls.List; 
    import fl.controls.TextInput; 

    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.events.MouseEvent; 

    public class EditableList extends Sprite 
    { 

     public function EditableList() 
     { 
      init(); 
     } 

     private function init():void 
     { 
      addName_bn.addEventListener(MouseEvent.CLICK, onAddName); 
      addName_ti.addEventListener(Event.CHANGE, onNameEnter); 
      addName_ti.addEventListener("enter", onAddName); 
      deleteName_bn.addEventListener(MouseEvent.CLICK, onDeleteName); 
      editName_ti.addEventListener("enter", onDeleteName); 
      editName_ti.addEventListener(Event.CHANGE, onNameChange); 
      names_li.addEventListener(Event.CHANGE, onNameSelected); 
      addEventListener(Event.ENTER_FRAME, onNextFrame); 
      addEventListener(Event.ENTER_FRAME, onFocus); 
      addName_ti.setFocus(); 

     } 

     private function onFocus(event:Event):void { 
      addName_ti.tabIndex = 0; 
      addName_bn.tabIndex = 1; 
      editName_ti.tabIndex = 2; 
      deleteName_bn.tabIndex = 3; 
     } 

     // Handler for when the next frame is reached after initialization, when buttons can be disabled. 

     private function onNextFrame(event:Event):void { 
      removeEventListener(Event.ENTER_FRAME, onNextFrame); 
      addName_bn.enabled = false; 
      deleteName_bn.enabled = false; 
      editName_ti.enabled = false; 
     } 

     // Handler for when the add name button is clicked, adds item to list. 

     private function onAddName(event:Event):void { 
      var newItem:Object = {label:addName_ti.text}; 
      names_li.dataProvider.addItem(newItem); 
      names_li.dataProvider.sortOn("label"); 
      addName_ti.text = ""; 
      addName_bn.enabled = false; 
      addName_ti.setFocus(); 
     } 

     // Handler for when text is entered into the add name textfield, enables the add name button. 

     private function onNameEnter(event:Event):void { 
      addName_bn.enabled = addName_ti.text.length > 0; 
     } 

     // Handler for when the delete name button is clicked, removes the list item. 

     private function onDeleteName(event:Event):void { 
      names_li.dataProvider.removeItemAt(names_li.selectedIndex); 
      deleteName_bn.enabled = false; 
      names_li.dataProvider.sortOn("label"); 
      editName_ti.text = ""; 
      editName_ti.enabled = false; 
      editName_ti.setFocus(); 
     } 

     // Handler for when text is changed into the edit name textfield, alters the item in the list. 

     private function onNameChange(event:Event):void { 
      var newItem:Object = {label:editName_ti.text}; 
      names_li.dataProvider.replaceItemAt(newItem, names_li.selectedIndex); 
     } 

     // Handler for when an item is selected in the list, populates fields and enables buttons. 

     private function onNameSelected(event:Event):void { 
      editName_ti.text = names_li.selectedItem.label; 
      editName_ti.enabled = true; 
      deleteName_bn.enabled = true; 
     } 

    } 

} 

回答

1

嘗試將InteractiveObject.tabEnabled屬性爲true你想選擇使用Tab鍵任何按鈕。另外,如果按鈕包含在父剪輯中,則還需要將父項tabChildren屬性也設置爲true。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/InteractiveObject.html#tabEnabled

+0

不知道我應該如何將它添加到按鈕。我在索引代碼上面同時嘗試了InteractiveObject(addName_ti).tabEnabled = true和addName_ti.tabEnabled = true,仍然沒有任何結果。 – Nerdysyntax 2012-04-07 20:05:02