views:

265

answers:

1

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>
A: 

your solution is described here

Eugene
the first suggested solution says "check that focusEnabled, tabFocusEnabled hasFocusableChildren are set properly." This does not work. The second solution suggests making sure that the formerly said properties are set on whatever skin you are using. I'm not using a skin. Plus I'm pretty sure that post is referring to flex 4. I am using flex 3
dubbeat
hm, okay, I need research a bit more and will let you know asap. While I'm researching try this hack `focus=new FocusManager(this);` inside of init function of TileWindow
Eugene
sadly that doesnt work. It's strange because when I first press the tab button I get the error. When I dismiss the error the rest of the items in the form tab select normally
dubbeat
could you post the output of exception here?
Eugene
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/getChildIndex() at mx.core::Container/getChildIndex() at mx.containers::Panel/getChildIndex() at fl.managers::FocusManager/getChildIndex() at fl.managers::FocusManager/sortByDepth()
dubbeat
It's like the title window isnt getting focus. I would of thought that automatically gets focus because its in the "front". Even after explicitly setting the focus the error persits. Not sure what other angles to attack this from
dubbeat
could you share a demo project, so I'll have access to modify it in your case.
Eugene