5 Replies Latest reply on Aug 17, 2009 11:53 PM by _Natasha_

    How to access a nested child tag values in  XML Object(getting error:No Such variable)

    satyamurthy_hyd

      Hi,

      I could see the XML object data and while accessing a perticular attribute let say "SlotA"  it is showing "No such variable Error".

      I appreciate any of your  inputs or suggestions to solve this error.

      You can find the screen snapshot of the problem as part of the attachment here.

      Thanks in advance

      CSNPrasad.

        • 1. Re: How to access a nested child tag values in  XML Object(getting error:No Such variable)
          _Natasha_ Level 4

          it's usual thing for FB debugger.

          try to trace variables you need to check values.

          • 2. Re: How to access a nested child tag values in  XML Object(getting error:No Such variable)
            satyamurthy_hyd Level 1

            Hi,

            thanks for the mail.

            Pls find the attachment,so that you can understand the problem description where i'm looking help from you?

            Thanks&regards

            • 3. Re: How to access a nested child tag values in  XML Object(getting error:No Such variable)
              _Natasha_ Level 4

              I've seen your attachment.

              Do you get this error or it's just a message in the variables window in debugger mode?

               

              If you don't get a error in runtime, it's a normal for xml variables in FB debugger. In this case I usually call trace(variable) for debug.

              • 4. Re: How to access a nested child tag values in  XML Object(getting error:No Such variable)
                satyamurthy_hyd Level 1

                Dear Natasha,

                Thanks for your mails & cooperation as well.

                This time i  have added the trace() and can see the value.Now the problem is "can't access a property or method of a null object reference"

                Noe: This code mxml file is called at Runtime based on the data defined in the XMLSocket data.

                I need to display Remote devices like davice1,device2 device3 etc. these are added/delete at any time ,so we need to show same changes in UI at Runtime.

                I implemented Polymorphism concept to construct the device object at runtime like follows

                var device:Object;

                for each (var deviceData:XML indeviceListXML..Device)

                                {

                                    device = getBatteryBay(deviceData.deviceId)

                                    // If device already exists with the deviceId, update the details

                                    // Else create a newdevice and add it to the container for displaying it.

                                                                                                if (device == null)

                                    {

                                       

                                        if (device.Type == "DEVICE1")

                                            device = new Device1();

                                        else if (device.Type == "DEVICE2")

                                        device = new Device2();

                                        else

                                            device = new DefaultDevice();

                                       

                                        device.id = deviceData.deviceId;

                                      device.name = deviceData.devicename;

                                     device.setData(deviceData);

                }

                Here new Device1(); and new Device2() are the UIComponents and created at Runtime, upto here no problem to display, when i try to setData to the devices it is throwing error

                "can't access a property or method of a null object reference". because Device1 and Device2 has Child components like "DataIndicator" and need to set properties to these components which are not created yet.

                 

                I appreciate any of your Input or suggestions at the earliest

                Thanks in Advance

                Regards

                 

                 

                 

                • 5. Re: How to access a nested child tag values in  XML Object(getting error:No Such variable)
                  _Natasha_ Level 4

                  For constructions like this it's better to use switch.

                   

                  if (device.Type == "DEVICE1")

                                              device = new Device1();

                                          else if (device.Type == "DEVICE2")

                                          device = new Device2();

                                          else

                                              device = new DefaultDevice();

                   

                  For UIComponents it's need to be careful when you need to set data.

                  There are two ways to solve this problem.

                  1. addEventListener for "creationComplete" event. And set data in handler.

                  2. Create a component with bindings. So you set properties of the component (number's, string's, array). And innerControls use this data throw data binding.