Yes your code works since its not dynamically building the form but what
happens if you try this code...it gets an error like i do

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical" horizontalAlign="left" creationComplete="loaditem()" >
<mx:Script>
<![CDATA[
import mx.controls.Alert;
     import mx.controls.TextInput;
             import mx.managers.PopUpManager;
             import mx.rpc.events.ResultEvent;
             import mx.rpc.events.FaultEvent;
             import mx.controls.Alert;
             import mx.controls.ComboBox;
             import mx.controls.Text;
             import mx.controls.RadioButton;
             import mx.controls.RadioButtonGroup;
             import mx.controls.Label;
             import mx.collections.ArrayCollection;
             import mx.controls.dataGridClasses.DataGridColumn;
             import mx.controls.TextArea;
             import mx.events.*;
             import mx.validators.*;
             import mx.managers.ToolTipManager;
             import mx.managers.IFocusManager;
             import mx.managers.IFocusManagerComponent;
             import mx.core.Container;
             import mx.controls.Alert;
             import mx.core.ComponentDescriptor;
             import flash.utils.*;
             import flash.net.navigateToURL;
             import flash.net.URLRequest;
             import flash.net.URLVariables;

public function loaditem(){

                         create_text = new TextInput();
                         create_text.id = "tester";
                         create_text.text =create_text.id;
                         dataBox.addChild(create_text);
}

private function showText(evt:MouseEvent):void{



var test:TextInput = this.getChildByName("tester") as TextInput;
Alert.show(test.text);
traceDisplayList(this);
}

public function traceDisplayList(container:DisplayObjectContainer,
indentString:String = "->"):void{
     var child:DisplayObject;
     for (var i:uint=0; i < container.numChildren; i++)
     {
         child = container.getChildAt(i);
         trace(indentString, child, child.name);
         if (container.getChildAt(i) is DisplayObjectContainer)
         {
             traceDisplayList(DisplayObjectContainer(child), "    " +
indentString)
         }
     }
}
]]>
</mx:Script>
<mx:VBox id="dataBox"></mx:VBox>

<mx:TextInput id="test1"/>
<mx:Button label="Button" click="showText(event)"/>
</mx:Application>





--- In [email protected], Nik Derewianka <[EMAIL PROTECTED]> wrote:
>
> That #1009 error means that it returned a null from the first line
> because it couldn't find the child with that name.   getChildByName is
> not recursive so you need to be mindful of the nesting of your
> requested object.
>
> The following app has the functionality working as you need it, but it
> also has a really handy listing function that displays all of the
> current children recursively (outputs to the console window in Flex,
> if you have the debug player) so that you can see the children that
> are present and how they are nested.
>
> Regards,
> Nik
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="vertical" horizontalAlign="left">
>  <mx:Script>
>   <![CDATA[
>    import mx.controls.Alert;
>    private function showText(evt:MouseEvent):void{
>     var test:TextInput = this.getChildByName("test" + 1) as TextInput;
>     Alert.show(test.text);
>     traceDisplayList(this);
>    }
>
>    public function traceDisplayList(container:DisplayObjectContainer,
> indentString:String = "->"):void{
>        var child:DisplayObject;
>        for (var i:uint=0; i < container.numChildren; i++)
>        {
>            child = container.getChildAt(i);
>            trace(indentString, child, child.name);
>            if (container.getChildAt(i) is DisplayObjectContainer)
>            {
>                traceDisplayList(DisplayObjectContainer(child), "    "
> + indentString)
>            }
>        }
>    }
>   ]]>
>  </mx:Script>
>
>  <mx:TextInput id="test1"/>
>  <mx:Button label="Button" click="showText(event)"/>
> </mx:Application>
>


Reply via email to