Using Tab Focus Manager In A Title Window Flex
I'm struggling to get around an error that is constantly thrown in my application when I press the tab key.
I have a modal dialog box that contains a form with 3 form items. Whenever I press the tab button flex throws an error saying
"ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller."
I've tried setting up a focus manager in the initilize handler of my title window to no avail
private function init(e:FlexEvent):void
{
focus=new FocusManager(myform);
focus.setFocus(firsttextfield);
}
Error Output
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()
Full Title Window Code
<?xml version="1.0" encoding="utf-8"?>
&开发者_如何学JAVAlt;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>
I had a very similar problem that was driving me crazy. My solution ended up being to first activate the focusManager in the creationComplete handler of my TitleWindow.
protected function titleWindow_creationCompleteHandler(event:FlexEvent):void
{
this.focusManager.activate();
this.focusManager.setFocus(this.firstTextField);
}
精彩评论