I have spent the day trying to understand how to get a dynamically-backed 
hierarchical popup menu to work (within a ControlBar). I have gone from a 
fairly 
complex starting point to a minimal test case - and things are still not 
working. I am seeing three failures, depending on how I attempt this feat.

I have an ArrayCollection which is static (thanks to posting by Peter Ent):

        public var componentsAC:ArrayCollection = new ArrayCollection(
                [
                        { name: "Polygon_1", data: "top", children: new 
ArrayCollection(
                                [
                                { name: "Line_sement_2" },
                                { name: "Line_sement_3" },
                                { name: "Line_sement_4" },
                                { name: "Line_sement_5" }
                                ])
                        }
                ]);

a Tree and a PopUpButton:

        private var popbComponents:PopUpButton = new PopUpButton();
        private var treeComponents:Tree = new Tree();

and I have a utility method with a couple of boolean arguments for testing 
purposes.

        private function makeComponentsUI(usePopUpButton:Boolean, 
                                                                                
validateProps:Boolean=false):void
                {
                treeComponents.showRoot = true;
                treeComponents.labelFunction = treeLabel;
                treeComponents.dataProvider = componentsAC;
                if (usePopUpButton)
                        {
                        popbComponents.popUp = treeComponents;
                        popbComponents.label = "Components";
                        if (validateProps)
                                popbComponents.validateProperties();
                        addChild(popbComponents);
                        return;
                        }
                // else
                addChild(treeComponents);
                }

and I have three cases:

1.  Call this.makeComponents(false, false)

Tree shows up but seems to, somehow, remove all the other buttons and sliders 
that precede it in my subclass of ControlBar. This is lacking the popup 
aspect and would take much more real estate than it merits, but otherwise is 
okay.

2. Call this.makeComponents(true, false)

I get this:

TypeError: Error #1009: Cannot access a property or method of a null object 
reference.
        at 
mx.controls::PopUpButton/commitProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\PopUpButton.as:469]
        at 
mx.core::UIComponent/validateProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:5670]
        at 
mx.managers::LayoutManager/validateProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:519]
        at 
mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:669]
        at Function/http://adobe.com/AS3/2006/builtin::apply()
        at 
mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8460]
        at 
mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8403]

which seems related to another topic that was discussed - except that I do not 
think that I am removing anything from the stage (at least not knowingly).

3. Call this.makeComponents(true, true)

It doesn't crash, so that's good, I guess ;-) But all I get is a popup button 
labeled "Components" - but which lacks any popup-ness.

I would prefer to find a solution that works with ArrayCollection instead of 
with XMLListCollection. And, fwiw, I was able to get things working with a Menu 
and ComboBox, but that lacked the hierarchical aspect.

Thanks for any help with this.
-eric




Reply via email to