Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > DataSet component > DataSet.filtered | |||
Flash Player 7.
Flash MX Professional 2004.
dataSetInstance.filtered
Property; a Boolean value that indicates whether the data in the current iterator is filtered. The default value is false.When this property is true, the filter function specified by DataSet.filterFunc is called for each item in the collection.
In the following example, filtering is enabled on the DataSet object named employee_ds. Suppose that each record in the DataSet collection contains a field named empType. The following filter function returns true if the empType field in the current item is set to "management"; otherwise, it returns false.
employee_ds.filtered = true;
employee_ds.filterFunc = function (item:Object) {
// Filter out employees who are managers.
return(item.empType != "management");
};
The following example populates a DataGrid component from content dynamically loaded using the XMLConnector component. When a user clicks a CheckBox instance on the Stage, the contents of the DataSet component are filtered and are updated automatically in the DataGrid component.
Drag the following components to the Stage, and give them the following instance names:
editorsChoice_ch)reviews_dg)reviews_ds)reviews_xmlconn)Download a copy of the following XML document and save it to your local hard disk: http://www.helpexamples.com/flash/xml/reviews.xml. This XML document will be loaded dynamically using the XMLConnector component, but you'll use the local copy to import the XML schema into the DataSet component. Select the XMLConnector instance on the Stage and select the Schema tab from the Component inspector. Select the results property and click the "Import a schema from a sample XML file" button. Select the XML document that you downloaded to your local hard disk and click Open. The schema of the XML document should be imported into the DataSet component. With the reviews_xmlconn XMLConnector instance still selected on the Stage, add a binding from the reviews_xmlconn.results.reviews.review array to the dataProvider property of the reviews_ds DataSet instance. Set the direction of the data binding to "out" in the Bindings tab. Select the reviews_ds DataSet instance on the Stage and add another binding for the dataProvider property. With the reviews_ds instance selected, select the Bindings tab of the Component inspector. Click the Add binding button and add a binding from the dataProvider property of the DataSet component to the dataProvider property of the reviews_dg DataGrid instance.
Add the following code to Frame 1 of the main timeline:
editorsChoice_ch.label = "Editor's Choice";
reviews_xmlconn.direction = "receive";
reviews_xmlconn.multipleSimultaneousAllowed = false;
reviews_xmlconn.URL = "http://www.helpexamples.com/flash/xml/reviews.xml";
reviews_xmlconn.trigger();
reviews_dg.setSize(320, 240);
reviews_dg.addColumn("name");
reviews_dg.addColumn("rating");
reviews_dg.addColumn("reviewDate");
reviews_dg.getColumnAt(0).width = 100;
reviews_dg.getColumnAt(1).width = 100;
reviews_dg.getColumnAt(2).width = 100;
reviews_dg.setStyle("alternatingRowColors", [0xFFFFFF, 0xF6F6F6]);
editorsChoice_ch.addEventListener("click", editorsChoiceListener);
function editorsChoiceListener(evt_obj:Object):Void {
reviews_ds.filtered = evt_obj.target.selected;
reviews_ds.filterFunc = function(item:Object):Boolean {
return (item.editorsChoice == 1);
};
}
Select Control > Test Movie. By default, the DataGrid component should display each of the reviews from the external XML document. Clicking on the Editor's Choice CheckBox component causes the DataSet component to be filtered, so that only the specific reviews flagged as an editor's choice appear.
Flash CS3