6 Replies Latest reply on Apr 15, 2008 4:53 AM by Bob Pierce

    Help using DataSet component please

    Bob Pierce Level 1
      I'd like to use the DataSet component's find() function on data that's not bound to anything, eg DataGrid etc. The following test code appears to work with various other DataSet methods but not with find(). Am I making some minor error or is the whole approach wrong? Do I need to import another component?

      import mx.data.components.DataSet;
      import mx.data.components.datasetclasses.DataSetIterator;

      stateName = new Array("Alabama","Alaska","Arizona","West Virginia","Wisconsin","Wyoming");
      stateAbbrv = new Array("AL","AK","AZ","WV","WI","WY");

      stateSource = new Array();

      for (i=0; i<stateName.length; i++) {
      stateSource.addItem({label:stateName , data:stateAbbrv});

      state_ds = new DataSet();
      state_ds.items = stateSource;

      trace(state_ds.getLength()); // > 6

      trace("Before sort() > " + state_ds.currentItem.label); // > Alabama

      trace("After next() > " + state_ds.currentItem.label); // > Alaska

      state_ds.addSort("nameSort", ["label"], DataSetIterator.Descending );
      trace("After sort() > " + state_ds.currentItem.label); // > Wyoming

      if (state_ds.find(["Wisconsin"])) { // fails
      stateID = state_ds.getItemId();
      trace("After find() > " + state_ds.currentItem.label);
      } else {
      trace("Find failed");
        • 1. Re: Help using DataSet component please
          Neat Gadget Level 1
          I tried out your code and got the same results as you. I can't see where the problem is either. I know that doesn't help but I'll continue to try and find out why.

          One question, and I know this probably comes across as a bit of a novice question, but do you have to put the lines

          import mx.data.components.DataSet;
          import mx.data.components.datasetclasses.DataSetIterator;

          on every frame that you are using the DataSet component?
          • 2. Re: Help using DataSet component please
            rlc5611 Level 1
            You left out a step
            • 3. Re: Help using DataSet component please
              rlc5611 Level 1
              I pulled some info I had in an old FLA and added a combobox. This script requires that the combobox be placed in the library of the FLA.

              This will place the state names in one combobox and field names of the object array in a second combobox that can be used for sorting.

              Selecting a state name traces out (in test mode) the infor found for that state.

              Selecting from the other combobox will sort the data set based on that parameter and repopulate the state name combobox in descending order for the item sorted on.
              • 4. Re: Help using DataSet component please
                Bob Pierce Level 1
                What a splendid response. Thanks for your time rlc5611, those two lines did the trick. I get the point about "label" and "data" they were a carry over from the combobox dataProvider which is where this quest started.

                Could you clarify what these two lines do? They appear not only to specify a data type for each property - both string - but to declare them as variables. The following (rather confusing) extract from the components reference shows similar lines described as schema types. The two lines specify one variable per data type, rather than specifying a data type for each of the three properties involved. Is this a different process to the one you describe? How do i and j, get applied to id, firstName and lastName?

                Thanks again.

                Extract from components reference - Creating an application with the DataSet component:

                Add the three properties and their required data types to the DataSet schema:
                Select the DataSet component on the Stage, open the Component inspector, and click the Schema tab.
                Click Add Component Property, and add three new properties, with field names id, firstName, and lastName, and data types Number, String, and String, respectively.
                Or, if you prefer to add the properties and their required data types in code, you can add the following line of code to the Actions panel instead of following steps a and b above:
                // Add required schema types.
                var i:mx.data.types.Str;
                var j:mx.data.types.Num;
                • 5. Re: Help using DataSet component please
                  rlc5611 Level 1
                  Actually I think you are right in that you only have to load once the data type you will be using so the script in the help file will work.
                  • 6. Re: Help using DataSet component please
                    Bob Pierce Level 1
                    Thanks very much.