2010-09-07 70 views
2

當我按Tab鍵時,我正努力解決在應用程序中不斷拋出的錯誤。在標題窗口中使用Tab鍵焦點管理器Flex

我有一個模態對話框,其中包含一個窗體與3個表單項。每當我按標籤按鈕彎曲拋出一個錯誤說

「ArgumentError:錯誤#2025:提供的DisplayObject必須是調用方的子項。」

我試着在我的標題窗口的用來初始化處理焦點管理器設置無濟於事

private function init(e:FlexEvent):void 
      { 

       focus=new FocusManager(myform); 
       focus.setFocus(firsttextfield); 
      } 

錯誤輸出

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. 
    at flash.display::DisplayObjectContainer/getChildIndex() 
    at mx.core::Container/getChildIndex()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\Container.as:2450] 
    at mx.containers::Panel/getChildIndex()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\containers\Panel.as:1032] 
    at fl.managers::FocusManager/getChildIndex() 
    at fl.managers::FocusManager/sortByDepth() 
    at Array$/_sort() 
    at Array/http://adobe.com/AS3/2006/builtin::sort() 
    at fl.managers::FocusManager/sortFocusableObjects() 
    at fl.managers::FocusManager/keyDownHandler() 

全稱窗口代碼

<?xml version="1.0" encoding="utf-8"?> 
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" 
       layout="absolute" 
       width="400" 
       height="400" 
       showCloseButton="true" 
       close="titleWindow_close(event);" 
       creationComplete="init(event)" 
       title="Save Widget"> 

    <mx:Script> 
     <![CDATA[ 
      import mx.managers.FocusManager; 
      import mx.validators.Validator; 
      import mx.events.ItemClickEvent; 
      import mx.events.CloseEvent; 
      import mx.managers.PopUpManager; 
      import mx.events.FlexEvent; 

      public var targetComponent:Create 
      public var bpm:int; 
      public var focus:FocusManager 

      private function init(e:FlexEvent):void 
      { 
       addEventListener(Event.ENTER_FRAME, validateUs, false, 0, true) 
       widgettitle.text=targetComponent._title; 
       genre.text=targetComponent._genre; 
       tags.text=targetComponent._tags 
       //focus=new FocusManager(saveform); 
       //focus.setFocus(widgettitle); 
      } 


      private function titleWindow_close(evt:CloseEvent):void 
      { 
       removeEventListener(Event.ENTER_FRAME, validateUs) 
       PopUpManager.removePopUp(this); 
      } 




      private function submitForm():void 
      { 
       //targetComponent.issueSaveRemixRequest() 
       PopUpManager.removePopUp(this); 
       targetComponent._genre=genre.text 
       targetComponent._tags=tags.text 
       targetComponent._title=widgettitle.text 
       targetComponent.doSave() 

      } 

      private function validateUs(event:Event):void 
      { 
       if (widgettitle.text.length >= 4 && genre.text.length >= 3 && tags.text.length >= 3) 
       { 
        submitbutton.enabled=true 
       } 
       else 
       { 
        submitbutton.enabled=false 

       } 
       //submitbutton.enabled=(Validator.validateAll([val1, val2,val3]).length == 0); 
      } 
     ]]> 
    </mx:Script> 
    <mx:Form id="saveform" 
      width="90%" 
      height="90%"> 
     <mx:FormHeading label="Fill Out Fields To Save"/> 
     <mx:FormItem label="Title"> 
      <mx:TextInput id="widgettitle" 
          width="100%"/> 
     </mx:FormItem> 

     <mx:FormItem label="Genre"> 
      <mx:TextInput id="genre" 
          width="100%"/> 
     </mx:FormItem> 

     <mx:FormItem label="Tags (comma seperated)"> 
      <mx:TextInput id="tags" 
          width="100%"/> 
     </mx:FormItem> 

     <mx:FormItem> 
      <mx:HRule width="200" 
         height="1"/> 
      <mx:Button label="Submit" 
         click="submitForm();" 
         id="submitbutton"/> 
     </mx:FormItem> 


    </mx:Form> 

    <mx:StringValidator source="{widgettitle}" 
         property="text" 
         minLength="4" 
         required="true" 
         id="val1"/> 
    <mx:StringValidator source="{genre}" 
         property="text" 
         minLength="3" 
         required="true" 
         id="val2"/> 
    <mx:StringValidator source="{tags}" 
         property="text" 
         minLength="3" 
         required="true" 
         id="val3"/> 




</mx:TitleWindow> 
+0

請提供您的對話框的代碼併發布此異常的堆棧跟蹤 - 這真的會有所幫助。 – 2010-09-07 12:17:35

回答

1

我有一個非常類似的問題,這讓我發瘋。我的解決方案最終是在我的TitleWindow的creationComplete處理程序中首先激活focusManager。

protected function titleWindow_creationCompleteHandler(event:FlexEvent):void 
{ 
    this.focusManager.activate(); 
    this.focusManager.setFocus(this.firstTextField); 
}