开发者

viewstack causing error 1065 variable not defined issue?

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 refr开发者_StackOverflow中文版esh/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(selectedNode.@hidden.toString() + " *");

            if(selectedNode.@hidden.toString() == '' || selectedNode.@hidden.toString() == null){
                //Alert.show("NULL !");
                return;
            }


            mainviewstack.selectedChild = Container(mainviewstack.getChildByName(selectedNode.@hidden.toString())); //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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜