The children of navigators (TabNavigator, ViewStack, Accordion, etc) don't
get created until they are shown. So the second child VBox in your
TabNavigator doesn't exist until you select that tab (or manually set the
selectedChild like you do in your AS code). But it takes a little while for
the child to be created, and when you try to access a child component within
that VBox immediately it fails. The second time you try it has already been
created, so it works fine.

For a quick fix you can probably just use callLater and change the line in
jumpTab to:
callLater(drawXMLForm);

or you can use binding to make it all even simpler and just do this:
<mx:Text id="xmlForm" text={xmlString.text}">

then you wouldn't even need to set the text of xmlForm via AS at all.

Doug

On 12/24/07, zlayde <[EMAIL PROTECTED]> wrote:
>
>   I'm kind of new to Flex so this is most likely due to my newness.
>
> I'm trying to redisplay the XML dropped in one tab into a second tab.
> The first time u click the "Edit XML" button, I get this error:
>
> TypeError: Error #1009: Cannot access a property or method of a null
> object reference.
>
> Now, if I try AGAIN, it works fine. If I refresh the page in the browser
> it works fine also. It's just hte first time I hit that 'Edit XML'
> button. Any ideas?
>
> Thanks in advance,
> Rich
>
> The code:
>
> <?xml version="1.0"?>
> <!-- Simple example to demonstrate the TabNavigator layout container.
> -->
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; >
>
> <mx:Script>
> <![CDATA[
>
> private function jumpTab():void {
> tn.selectedChild = editTab;
> drawXMLForm();
> }
> private function drawXMLForm():void {
> xmlForm.text = xmlString.text;
> }
> ]]>
> </mx:Script>
>
> <mx:Panel title="MAXE 0.01" height="90%" width="90%"
> paddingTop="10" paddingLeft="10" paddingRight="10"
> paddingBottom="10">
>
> <mx:Label width="100%" color="blue"
> text="Select the tabs to change the panel."/>
>
> <mx:TabNavigator id="tn" width="100%" height="100%">
>
> <mx:VBox label="Drop XML" paddingLeft="20" paddingRight="20"
> paddingBottom="20" id="dropTab">
> <mx:Label text="Drop Your XML text right here"/>
>
> <mx:TextArea id="xmlString" width="100%" height="100%"
> text="">
>
> </mx:TextArea>
> <mx:HBox width="100%" horizontalAlign="right">
> <mx:Button label="Edit XML" id="editXML"
> click="jumpTab();" />
> </mx:HBox>
>
> </mx:VBox>
>
> <mx:VBox label="Edit XML" id="editTab" paddingLeft="20"
> paddingRight="20" paddingBottom="20">
> <mx:Text id="xmlForm">
> <mx:text></mx:text>
> </mx:Text>
> </mx:VBox>
>
> </mx:TabNavigator>
>
> </mx:Panel>
> </mx:Application>
>
>  
>

Reply via email to