当我按Tab键时,我正在努力解决我的应用程序中经常出现的错误。
我有一个模态对话框,其中包含一个包含3个表单项的表单。每当我按下tab键时,flex就会抛出一个错误
“ArgumentError:错误#2025:提供的DisplayObject必须是调用者的子级。”
我已尝试在我的标题窗口的initilize处理程序中设置焦点管理器无效
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 :(得分:1)
我有一个非常类似的问题让我发疯。我的解决方案最终是首先在我的TitleWindow的creationComplete处理程序中激活focusManager。
protected function titleWindow_creationCompleteHandler(event:FlexEvent):void
{
this.focusManager.activate();
this.focusManager.setFocus(this.firstTextField);
}