views:

238

answers:

1

I've got an flex application where I have a left side TREE control and a viewstack on the right and when someone selects the tree it loads the named viewstack based on the hidden node value of the XML of the tree. But it's throwing a error 1065 variable not defined on a viewstack which worked on the last browser refresh/reload. It's not related to a particular viewstack from what I can tell it just seems to throw the error on certain render events. I've tried to use creationpolicy="all" on the viewstack but it seems to not be of any help.

public function treeChanged(event:Event):void {

            selectedNode=Tree(event.target).selectedItem as XML;
            //trace(selectedNode.@hidden);
            //Alert.show([email protected]() + " *");

            if([email protected]() == '' || [email protected]() == null){
                //Alert.show("NULL !");
                return;
            }


            mainviewstack.selectedChild = Container(mainviewstack.getChildByName([email protected]())); //Container(mainviewstack.getChildByName(selectedNode.@hidden));

If I add in an alert box before the getchildbyname option the viewstack has time to render and everything works fine, so it leads me to believe the app is not giving it enough time to load the viewstack?

A: 

Where exactly does the error happen? Do you have a stacktrace? Where do you register the event listener treeChanged()?

You might try to add the event listener in an event listener for FlexEvent.CREATION_COMPLETE. All components should have been initialized by that time.

the way you add your event listener looks correct to me but I'm not sure about the timing. So here's an example of adding the event listener for CREATION_COMPLETE (assuming that a canvas is your containing element):

<mx:Canvas creationComplete="onCreationComplete">
    <mx:Script><![CDATA[
            private function onCreationComplete():void {
                tree.addEventListener(TreeEvent.Change, treeChange)
            }
        ]]>
    </mx:Script>
    <mx:Tree id="tree" ... />
</mx:Canvas>

Please not that I haven't tested this, I just wrote that down on the go. Some names might be wrong but it should give you the right idea.

ilikeorangutans
The error happens on line mainviewstack.selectedChild = Container(mainviewstack.getChildByName([email protected]())); //Container(mainviewstack.getChildByName(selectedNode.@hidden));I register the tree change here<mx:Tree id="RootTree" width="15%" height="100%" labelField="@label" showRoot="false" dataProvider="{treeData}" change="treeChanged(event)"/>Can you give an example on how I can use the FlexEvent.creation complete?
jason
Im also using flex sdk 3.0 should I upgrade it?
jason
ReferenceError: Error #1065: Variable is not defined. at global/flash.utils::getDefinitionByName() at mx.utils::DescribeTypeCache$/describeType()[C:\autobuild\3.4.0\frameworks\projects\framework\src\mx\utils\DescribeTypeCache.as:95] at mx.utils::ObjectUtil$/getClassInfo()[C:\autobuild\3.4.0\frameworks\projects\framework\src\mx\utils\ObjectUtil.as:838] at mx.controls::DataGrid/generateCols()[C:\autobuild\3.4.0
jason
just upgraded to sdk 3.4.1error happens right on application load
jason
still having a problem with this error? very frustrating i removed all references to any calls in actionscript and recompiled and still get this error on app loading?
jason