4 Replies Latest reply on Jun 13, 2007 4:53 PM by yu.wei.qian.07

    If we have Id of an Object,Can i create an object..

    Ashish Mishra
      Hi friends,

      I have the id the component say it is in TextInput. So can I create an InputText with same id, (like cloning the object). IS there anything present in flex, n get the values of that object?

      Thanks for ur answers.

        • 1. Re: If we have Id of an Object,Can i create an object..
          levancho Level 3
          if you have an id that means that object already exists with public modifier, DOC says you can access it by just reffering it by its id in action script. for example say if ID='TextInput" in A/S you should be able to do:
          TextInput.methodName() etc ..
          • 2. Re: If we have Id of an Object,Can i create an object..
            Ashish Mishra Level 1
            Hi Friends, Check the code u will get the Idea:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pageInit();">
            import mx.utils.ObjectUtil;
            import mx.events.ListEvent;
            import mx.controls.Alert;

            public var noOfColumns:int;

            public function pageInit():void{
            noOfColumns = vbFieldNames.getChildren().length;

            public function showMessage(event:Event):void{
            //var result:String = event.currentTarget.selectedItem.id + " " +event.currentTarget.selectedIndex + "\n";
            Alert.show("Values is changed: ");
            public function checkPrecisionApplicability (control:ComboBox):void{
            var controlId:String = control.id;
            var dispObject:DisplayObject ; dispObject = vbFieldPrecision.getChildAt(noOfColumns);
            noOfColumns = vbFieldType.getChildIndex(control);
            if(control.selectedItem == "DATE"){
            dispObject.visible = false;
            dispObject.visible = true; }
            public function showResults():void{
            var result:XML = new XML(httpCreateDB.lastResult);
            Alert.show("Result is === "+result.child("root").valueOf()+"\n"+httpCreateDB.lastResult.toString());

            public function sendCreateRequest():void{
            var params:Object = new Object();
            if(iptTableName.text != ""){
            params.tablename = iptTableName.text;
            Alert.show("Table name can not be empty");

            var dispFieldNameObj:Object;
            var strFieldName:String ;
            var txtFieldName:TextInput ;

            var paramValue:String ;
            Alert.show("no of columns : "+noOfColumns);
            for(var i:int=0; i<noOfColumns; i++){
            dispFieldNameObj = vbFieldNames.getChildAt(i);

            var iptFN:TextInput = new TextInput();
            iptFN.id = dispFieldNameObj.id;
            var value:String = iptFN.text;
            Alert.show("id of iptFieldName is == "+dispFieldNameObj.id+" n Its Value is : "+value+); }

            <mx:HTTPService id="httpCreateDB" url=" http://localhost:9090/StrutsDemo/create.do" resultFormat="xml" result="showResults();" />

            <mx:HBox x="12" y="20" width="100%" height="100%">
            <mx:VBox id="vbLabels" width="10%" height="100%">
            <mx:Text text="Enter Table Name" width="100%" height="20" textAlign="right"/>
            <mx:Spacer height="20" />
            <mx:Text text="Column" width="100%" height="20" textAlign="right" fontWeight="bold"/>
            <mx:Text text="Column1" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column2" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column3" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column4" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column5" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column6" width="100%" height="20" textAlign="right"/>
            <mx:Text text="Column7" width="100%" height="20" textAlign="right"/>

            <mx:VBox id="vbFields" width="20%" height="100%">

            <mx:VBox id="vbTableName" >
            <mx:TextInput id="iptTableName" width="100%" height="20" />

            <mx:Spacer height="20" />
            <mx:Text text="DataBase Field Name" width="100%" height="20" textAlign="center" fontWeight="bold"/>
            <mx:VBox id="vbFieldNames" width="100%" >
            <mx:TextInput id="iptCol1" width="100%" height="20" />
            <mx:TextInput id="iptCol2" width="100%" height="20"/>
            <mx:TextInput id="iptCol3" width="100%" height="20"/>
            <mx:TextInput id="iptCol4" width="100%" height="20"/>
            <mx:TextInput id="iptCol5" width="100%" height="20"/>
            <mx:TextInput id="iptCol6" width="100%" height="20"/>
            <mx:TextInput id="iptCol7" width="100%" height="20"/>

            <mx:Spacer height="20" />

            <mx:Button id="btnCreate" label="CreateDB" click="sendCreateRequest();" />

            Here in showResults(): I m taking all the Child of the three VBox. Now My Problem is that i want to retrieve the value of the controls. But the children() retrun an array of the DisplayObject().

            You can not get text, selectedItem properties from a display object. but here I have id of the objects.

            I m getting the id as : dispFieldNameObj.id. But when i say dispFieldNameObj.text. It won't give any error or value. If I say dispFieldNameObj.id.text. It gives following error:

            ReferenceError: Error #1069: Property text not found on String and there is
            no default value.
            at DB/sendCreateRequest()
            at DB/__btnCreate_click()

            can somebody tell me how to solve this problem? or How can I refer controls inside a container n access all its properties.

            thanks in advance for your reply..

            • 3. Re: If we have Id of an Object,Can i create an object..
              ntsiii Level 3
              I don't have the time or inclination to analyze your code. Restate your question if levancho's understanding is incorrect.

              • 4. Re: If we have Id of an Object,Can i create an object..
                try this:
                var theObject:TextInput = Container.getChildByName('NamePropertyOfYourTextInputButNotTheID');
                something = theObject.text;

                Declare the object as any type of control. the container could be the canvas or the vbox that hold your text input object.
                however to your question 'How can I refer controls inside a container n access all its properties?'

                why not use
                something = ObjectID.text ;

                if that doesn't answer, maybe you should clear the question. :)