5 Replies Latest reply on Jun 22, 2006 10:09 AM by dbohea

    Property Lists: How to insert a variable as a property?

    dbohea
      Hi.

      I am trying to insert a variable in place of a newly defined property to be added to a poroperty list.

      This would normally add a new a new property to a poroperty list :

      Database [#needtogetvariablehere] = typedPassword

      -- 'Database' is the property list, 'needtogetvariablehere' is the new poperty and 'typedPassword' is the new property's value - thisall works fine.

      I'd like to generate new property names dynamically using an editable text box. How do I replace the new property name ' nedtogetvariablehere' with a variable?

      I'm sure I've got to put some rounded brackets in somewhere but everything I try spits out a syntax error.

      eg:

      myVariable = "blablabla"

      Database [#(myVariable)] = typedPassword


      Any ideas?

      Thanks.
        • 1. Re: Property Lists: How to insert a variable as a property?
          Level 7
          look at the 'symbol' function.



          "dbohea" <webforumsuser@macromedia.com> wrote in message
          news:e7e3p7$mb2$1@forums.macromedia.com...
          > Hi.
          >
          > I am trying to insert a variable in place of a newly defined property to
          be
          > added to a poroperty list.
          >
          > This would normally add a new a new property to a poroperty list :
          >
          > Database [#needtogetvariablehere] = typedPassword
          >
          > -- 'Database' is the property list, 'needtogetvariablehere' is the new
          poperty
          > and 'typedPassword' is the new property's value - thisall works fine.
          >
          > I'd like to generate new property names dynamically using an editable
          text
          > box. How do I replace the new property name ' nedtogetvariablehere' with
          a
          > variable?
          >
          > I'm sure I've got to put some rounded brackets in somewhere but
          everything I
          > try spits out a syntax error.
          >
          > eg:
          >
          > myVariable = "blablabla"
          >
          > Database [#(myVariable)] = typedPassword
          >
          >
          > Any ideas?
          >
          > Thanks.
          >


          • 2. Re: Property Lists: How to insert a variable as a property?
            Level 7
            type these one at a time in the message window to see how it works

            g = [:]
            x = "abc"
            g[symbol(x)] = "123"
            put g

            -- [#abc: "123"]


            • 3. Re: Property Lists: How to insert a variable as a property?
              a¿ex Level 1
              use the setaprop() or addProp() function.

              setaprop() adds, if not existing and replaces, if the property already exists
              addProp() justs add the property and the value, so that it may occurr, that you have two equal properties.

              xx = <anylingodatatype>

              list.setaprop(xx, value)


              so you can:

              xx = #someSymbol
              yy = 5
              plist = [:]

              plist.setaprop(xx, yy)


              as well as:

              xx = ["anotherlist"]
              plist.setaprop(xx, yy)
              • 4. Re: Property Lists: How to insert a variable as a property?
                Level 7
                I don't know of a way, despite the responses so far, to convert a variable
                name to a symbol then to use it as a property. You must hard code it as you
                have seen in the responses.

                Craig

                --
                Craig Wollman
                Word of Mouth Productions

                phone 212 928 9581
                fax 212 928 9582
                159-00 Riverside Drive West #5H-70
                NY, NY 10032
                www.wordofmouthpros.com


                "dbohea" <webforumsuser@macromedia.com> wrote in message
                news:e7e3p7$mb2$1@forums.macromedia.com...
                > Hi.
                >
                > I am trying to insert a variable in place of a newly defined property to
                > be
                > added to a poroperty list.
                >
                > This would normally add a new a new property to a poroperty list :
                >
                > Database [#needtogetvariablehere] = typedPassword
                >
                > -- 'Database' is the property list, 'needtogetvariablehere' is the new
                > poperty
                > and 'typedPassword' is the new property's value - thisall works fine.
                >
                > I'd like to generate new property names dynamically using an editable text
                > box. How do I replace the new property name ' nedtogetvariablehere' with
                > a
                > variable?
                >
                > I'm sure I've got to put some rounded brackets in somewhere but everything
                > I
                > try spits out a syntax error.
                >
                > eg:
                >
                > myVariable = "blablabla"
                >
                > Database [#(myVariable)] = typedPassword
                >
                >
                > Any ideas?
                >
                > Thanks.
                >


                • 5. Property Lists: How to insert a variable as a property?
                  dbohea Level 1
                  Nice one folks.

                  Dave C's second reply seemed to do the trick.

                  May all your geese be swans.