4 Replies Latest reply on May 27, 2009 12:00 AM by GordonSmith

    Numeric object names

    benreed83 Level 1

      Hi guys, I hoep someone here can help...

       

      I am in the middle of wrting a search widget in Flex that searches a Drupal 6 site, all is going well but I have stumbled upon a bug in that I cannot access the properties of an object that has a numeric name. The data that is returned from Drupal is as follows:

       

      [0] (Object)#1
          binding = (Object)#2
            212 = (Object)#3
              description = "Suitable for people aged 18 years and up"
              name = "18"
              tid = "212"
              vid = "162"
              weight = "0"
            213 = (Object)#4
              description = "Digital Versatile Disc"
              name = "DVD"
              tid = "213"
              vid = "166"
              weight = "0"

       

      Now normally I would access the properties using the dot syntax as per usual, so it would be 'binding.212.name' for example, but Flex builder errors at this point as it doesn't like the numeric object name, I get the error:

       

      '1084: Sytnax error: expecting rightparen befor .212'

       

      Any help would be appreciated!

       

      Ben

        • 1. Re: Numeric object names
          Gregory Lafrance Level 6

          Can't have identifiers in Flex starting with numbers, so you'll have to change your data.

          • 2. Re: Numeric object names
            benreed83 Level 1

            I figured as much, only issue is this is the native format for getting results from Drupal, not too easy to change the core data. Oh well....

            • 3. Re: Numeric object names
              Gregory Lafrance Level 6

              Well, you might be able to iterate over the data in a for...in loop, and use obj[key] syntax or just use a for each...in loop, where you don't even deal with the keys, and stuff the data in a Flex structure of some sort. Not easy, but perhaps doable? You need to play with this a bit.

               

              Otherwise deal with repackaging the data on the server side.

              • 4. Re: Numeric object names
                GordonSmith Level 4

                Objects in ActionScript can have dynamic properties at runtime that have numeric names. (Previous responders are thinking about compile-time properties, which can't have such a name.) And instead of obj.foo you can write obj["foo"].

                 

                So, if you have obj:Object, then when you write either obj[212] or obj["212"] you are accessing a property whose name is the string "212". So you should be able to use binding[212].name or binding["212"].name to get what you want.

                 

                Gordon Smith

                Adobe Flex SDK Team