3 Replies Latest reply on May 12, 2007 3:43 AM by tomharding

    How can I build up an array based on 'checked' checkboxes?

    tomharding
      POO! Just realised this is in the wrong forum. Sorry

      Hey all.. I just have a question about forms in FLEX 2:

      I've got a repeater populated by a list of musicians taken from an XML file. Each artist is represented by a checkbox and when a submit button is clicked, I want that array to be sent over to a php script.

      This is the vbox containing the artist info and checkbox:


      <mx:VBox>
      <mx:Text text="{artistRepeat.currentItem.name}" />
      <mx:Image source =
      "{artistRepeat.currentItem.image}" scaleContent="true" />



      <mx:CheckBox data="{artistRepeat.currentItem.name}" id="cBox" click="modifyArray(Object)" />
      <mx:Text text="{cBox.data}" />

      </mx:VBox>


      And the function for handling this is:



      public function modifyArray(item:Object):String{
      if(cBox.data != null){
      return artistlist.text;

      }
      return artistlist.text = "(artist = "+cBox.data+")";;


      }


      This registers the artist as 'undefined'. Am I going the right direction here?

      Thanks,
      Tom
        • 1. Re: How can I build up an array based on 'checked' checkboxes?
          KomputerMan.com
          This is what I did to process the checkboxes. I put my checked checkboxes into a comma seperated string so I could process it as a list in Cold Fusiojn. I am sure you can modify this code a bit to populate an array instead of a list though. myCFNames is the name of my repeater too.

          var tmpCFCnt:String="";
          var firsttime:int = 0;

          for(var y:int = 0; y < myCFNames.length; y++)
          {
          if (myCFNames[y].selected == true)
          {
          if (firsttime == 0)
          {
          tmpCFCnt = myCFNames[y].validationSubField;
          }
          else
          {
          tmpCFCnt = tmpCFCnt + "," + myCFNames[y].validationSubField;
          }

          firsttime = firsttime + 1;
          }
          }

          Have an Ordianry Day...
          KomputerMan ~|:-)
          • 2. Re: How can I build up an array based on 'checked' checkboxes?
            tomharding Level 1
            Ok.. I've got this down here:

            [Bindable]
            public var artistArray:String;
            /*public var artistArray:ArrayCollection = null;
            */
            public function artistsReceived(item:Object):void
            {
            artistArray = new String(item.label);


            var artistArray:String="";
            var firsttime:int = 0;

            for(var y:int = 0; y < artistRepeat.length; y++)
            {
            if (artistRepeat[y].selected == true)
            {
            if (firsttime == 0)
            {
            artistArray = artistRepeat[y].validationSubField;
            }
            else
            {
            artistArray = artistArray + "," + artistRepeat[y].validationSubField;
            }

            firsttime = firsttime + 1;
            }
            }

            And the checkbox code still stays the same..

            However i'm getting a 1119 error in response to my repeater..

            Thanks for the reply anyway :)
            • 3. How can I build up an array based on 'checked' checkboxes?
              tomharding Level 1
              EDIT: Forget it. I've had it with this program. We're done.

              It's about a user friendly as a donkeys back hoof. Honestly, I'm never going to use this once I graduate, unless Adobe stop employing Russians to write their error messages and a decent support website somewhere be setup.

              I'm sorry, I feel bad enough that a program has nearly induced several heart attacks. It's not good for my health building in this :-)

              Thankyou anyway,
              Tom