4 Replies Latest reply on May 24, 2007 7:00 AM by Gorka Ludlow

    combobox lables

    Damon Edwards Level 3
      how do i populate the combobox component's labels from an external file?
        • 1. Re: combobox lables
          Gorka Ludlow Level 1
          Well first you'll need to read the external file using your favorite method (loadVars, XML, etc) then you'll have to loop through the data and add items to your combobox instance with the combobox_instance.addItem('label','data') method.

          Cheers
          Gorka
          • 2. Re: combobox lables
            Damon Edwards Level 3
            so if i set my xml up like this
            <?xml version="1.0"?>
            <label>
            <label1>blah blah</label1>
            <label2>blah blah</label2>
            </label>
            then id add this to actions

            var xml:XML = new XML();
            xml.ignoreWhite = true;
            xml.load("labels.xml")
            cb.addItem('label1");
            cbaddItem('label2");
            *dont need data*

            would that work?
            • 3. Re: combobox lables
              Damon Edwards Level 3
              trying that only put 'label1' and 'label2' in the combobox, not the actual data from the xml file...
              • 4. Re: combobox lables
                Gorka Ludlow Level 1
                let say you have a data.txt outside the movie like this:

                &Name=Gorka&
                &Website=http://www.aquigorka.com&

                I'd do something like this:

                var objLV:LoadVars() = new LoadVars();
                objLV.load('data.txt');
                objLV.onLoad=function(success:Boolean):Void{
                if(success){
                cmbinstance.addItem(this.Name, 0);
                cmbinstance.addItem(this.Website, 1);
                }else{
                trace('some'n wrong')
                }
                }

                That'd work. But if you really want to read from an xml file I'd suggest parsing the data from the xml into an array and then looping the array to dump the data into the combobox:

                var xmlData:XML=newXML();
                xmlData.load('your.xml');
                xmlData.onLoad=function(success:Boolean):Void{
                if(sucess){
                var ArrayData:Array= parsingfunction(this); // I leave this to you, if don't know how to parse the xml, let me know
                for(var i=0;i<ArrayData.length;i++)
                cmbinstance.addItem(ArrayData [0], i);
                }else{
                trace('not right');
                }
                }

                Cheers
                Gorka