3 Replies Latest reply on Jun 15, 2009 11:34 AM by Benji2008

    ArrayCollection

    lmcrun19

      I have an ArrayCollection playing mp3's from a mx:ComboBox. I am setting labels for each mp3 in my array. In mx:combobox  I set the labelfield to display the lable, but when I run the application and select a mp3 file I get an actionscript error. I believe its because I set the labelfield for the label but I did not set anything for the "File: "index7ex.mp3" itself. Basically, in my ComboBox what else do I input in order to select the file also. Also, if anyone sees anything else wrong with what I have , I thank you in advance if you could just let me know. Thanks.

       

      private var dp:ArrayCollection = new ArrayCollection([{ label: "My cool song", File: "index7ex.mp3"}, { label: "Another cool song", File: "index8ex.mp3"}  ])

       

       

      <mx:ComboBox creationComplete="cb.dataProvider=dp" id="cb" change="loadSound()" width="100%" labelField="label"/>

        • 1. Re: ArrayCollection
          Benji2008

          Maybe it wouldnt be a bad idea if you that Array Bindable,

          as for selecting the right value, I guess it depends what you do in your loadSound function,

          you must select the selectedItem-- ( cb.selectedItem.File ) - that way you can select the mp3 you want

           

          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.collections.ArrayCollection;
                  [Bindable]
                  private var dp:ArrayCollection = new ArrayCollection([{ label: "My cool song", File: "index7ex.mp3"}, { label: "Another cool song", File: "index8ex.mp3"}  ])
                 
                  private function loadSound():void
                  {
                      Alert.show(cb.selectedItem.File);
                  }
             
              ]]>
          </mx:Script>


          <mx:ComboBox dataProvider="{dp}" id="cb" change="loadSound()" width="100%" labelField="label"/>

           

          hope this helps

          • 2. Re: ArrayCollection
            lmcrun19 Level 1

            cb.selectedItem.File

             

            That did the trick. Thanks.

            • 3. Re: ArrayCollection
              Benji2008 Level 1

              you're welcome