6 Replies Latest reply on Oct 15, 2008 7:34 AM by Newsgroup_User

    convert mxml array to as3

    ccrum
      I've got the following array which uses a specail ListItemValueObject pacakage. The array is

      <mx:Array id="arr">
      <vo:ListItemValueObject label="One" isSelected="true" />
      <vo:ListItemValueObject label="Two" isSelected="true" />
      <vo:ListItemValueObject label="Three" isSelected="true" />
      <vo:ListItemValueObject label="Four" isSelected="true" />
      <vo:ListItemValueObject label="Five" isSelected="false" />
      <vo:ListItemValueObject label="Six" isSelected="false" />
      <vo:ListItemValueObject label="Seven" isSelected="false" />
      <vo:ListItemValueObject label="Eight" isSelected="false" />
      <vo:ListItemValueObject label="Nine" isSelected="false" />
      <vo:ListItemValueObject label="Ten" isSelected="false" />
      <vo:ListItemValueObject label="Eleven" isSelected="false" />
      <vo:ListItemValueObject label="Twelve" isSelected="false" />
      </mx:Array>

      and the package is

      /**
      * http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-i n-flex/
      */
      package {
      public class ListItemValueObject {
      [Bindable]
      public var label:String;


      [Bindable]
      public var isSelected:Boolean;

      public function ListItemValueObject() {
      super();
      }
      }
      }

      this is taken from a list with check box example online.

      What I want to do is convert that array to an AS3 array. I've tried this:

      private var arr:Array =
      [{vo:"ListItemValueObject" label="Routers" isSelected="true"},
      {vo:"ListItemValueObject" label="APs" isSelected="true"},
      {vo:"ListItemValueObject" label="Customers" isSelected="true"},
      {vo:"ListItemValueObject" label="Links" isSelected="true"}];
      [Bindable]

      but it doesn't work....any ideas?

      Cameron

        • 1. Re: convert mxml array to as3
          Level 7

          "ccrum" <webforumsuser@macromedia.com> wrote in message
          news:gd379d$pq$1@forums.macromedia.com...
          > I've got the following array which uses a specail ListItemValueObject
          > pacakage.
          > The array is
          >
          > <mx:Array id="arr">
          > <vo:ListItemValueObject label="One" isSelected="true" />
          > <vo:ListItemValueObject label="Two" isSelected="true" />
          > <vo:ListItemValueObject label="Three" isSelected="true" />
          > <vo:ListItemValueObject label="Four" isSelected="true" />
          > <vo:ListItemValueObject label="Five" isSelected="false" />
          > <vo:ListItemValueObject label="Six" isSelected="false" />
          > <vo:ListItemValueObject label="Seven" isSelected="false" />
          > <vo:ListItemValueObject label="Eight" isSelected="false" />
          > <vo:ListItemValueObject label="Nine" isSelected="false" />
          > <vo:ListItemValueObject label="Ten" isSelected="false" />
          > <vo:ListItemValueObject label="Eleven" isSelected="false" />
          > <vo:ListItemValueObject label="Twelve" isSelected="false" />
          > </mx:Array>
          >
          > and the package is
          >
          > /**
          > *
          > http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-
          > renderer-in-flex/
          > */
          > package {
          > public class ListItemValueObject {
          > [Bindable]
          > public var label:String;
          >
          >
          > [Bindable]
          > public var isSelected:Boolean;
          >
          > public function ListItemValueObject() {
          > super();
          > }
          > }
          > }
          >
          > this is taken from a list with check box example online.
          >
          > What I want to do is convert that array to an AS3 array. I've tried this:
          >
          > private var arr:Array =
          > [{vo:"ListItemValueObject" label="Routers" isSelected="true"},
          > {vo:"ListItemValueObject" label="APs" isSelected="true"},
          > {vo:"ListItemValueObject" label="Customers" isSelected="true"},
          > {vo:"ListItemValueObject" label="Links" isSelected="true"}];
          > [Bindable]
          >
          > but it doesn't work....any ideas?

          Try:

          private var arr:Array = new Array()
          var vo:ListItemValueObject;
          vo= new ListItemValueObject();
          vo.label="Routers";
          vo.isSelected=true;
          arr.push vo;
          vo = new ListItemValueObject();
          vo.label="APs"
          vo.isSelected=true;
          arr.push vo;
          ...

          HTH;

          Amy


          • 2. Re: convert mxml array to as3
            ntsiii Level 3
            The {} syntax is a shortcut that creates simple "Object" elements. You want instances of your class so that won't work for you. Instead. do something like this:

            var aListItems:Array = [];
            var livo:ListItemValueObject;
            //create first item
            livo = new ListItemValueObject ();
            livo.label = "routers"; //set the properties
            livo.isSelected = "true";
            aListItems.push(livo); //ad the vo to the array
            //create next next next item
            livo = new ListItemValueObject ();
            livo.label = "Aps";
            ...

            Tracy
            • 3. Re: convert mxml array to as3
              ntsiii Level 3
              Note: if you already have the array created, then you could loop over the elements of the array and build each "livo", instead of doing it manually for each element like I show above.

              Further, this techniques is the preferred way to use data from an RPC service. One technique that people use is to have a method on your VO that takes the data element (dto), whether it is an Object, or an XML node, as an argument and populates the VO properties itself. Much cleaner to code. For example:
              livo = new ListItemValueObject ();
              livo.fill(myDTO[ i ]);
              aListItems.push(livo);

              No big deal if you only have two properties on your VO, but if you had 25...
              Tracy
              • 4. Re: convert mxml array to as3
                ccrum Level 1
                Thanks for the tips. Now the only question is, how do I access the parts of object in each element to make a change. For instance, if I wanted to go back and change the isSelected value of the vo with the label "Routers", how do I access it? If I put the array into an array collection, will that make it easier?
                • 5. Re: convert mxml array to as3
                  Level 7

                  "ccrum" <webforumsuser@macromedia.com> wrote in message
                  news:gd4tuk$41r$1@forums.macromedia.com...
                  > Thanks for the tips. Now the only question is, how do I access the parts
                  > of
                  > object in each element to make a change. For instance, if I wanted to go
                  > back
                  > and change the isSelected value of the vo with the label "Routers", how do
                  > I
                  > access it? If I put the array into an array collection, will that make it
                  > easier?

                  MenuBarItem does not support a backgroundColor property, but MenuBar does
                  allow you to specify itemUpSkin, itemOverSkin, etc. You could also look at
                  providing your own itemRenderer, or dig through the code and see exactly
                  what kind of control is being popped up when the menu opens to look at its
                  styling options.

                  HTH;

                  Amy


                  • 6. Re: convert mxml array to as3
                    Level 7

                    "ccrum" <webforumsuser@macromedia.com> wrote in message
                    news:gd4tuk$41r$1@forums.macromedia.com...
                    > Thanks for the tips. Now the only question is, how do I access the parts
                    > of
                    > object in each element to make a change. For instance, if I wanted to go
                    > back
                    > and change the isSelected value of the vo with the label "Routers", how do
                    > I
                    > access it? If I put the array into an array collection, will that make it
                    > easier?

                    oops, sorry, answered wrong thead