在标题窗口 Flex 中使用选项卡焦点管理器

发布于 2024-09-18 05:29:20 字数 5090 浏览 5 评论 0原文

当我按 Tab 键时,我正在努力解决应用程序中不断抛出的错误。

我有一个模式对话框,其中包含一个带有 3 个表单项的表单。每当我按下选项卡按钮时,flex 都会抛出一个错误,提示

“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>

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"?>
<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪意 2024-09-25 05:29:24

我有一个非常相似的问题,这让我发疯。我的解决方案最终是首先在 TitleWindow 的creationComplete 处理程序中激活 focusManager 。

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文