(Beta)
Package | fl.data |
Class | public class DataProvider |
Inheritance | DataProvider ![]() ![]() |
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
A data provider is a linear collection of items that serve as a data source--for
example, an array. Each item in a data provider is an object or XML object that contains one or
more fields of data. You can access the items that are contained in a data provider by index, by
using the DataProvider.getItemAt()
method.
Public Properties
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object |
Public Methods
Method | Defined By | ||
---|---|---|---|
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | |
![]() |
Dispatches an event into the event flow. | EventDispatcher | |
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Removes a listener from the EventDispatcher object. | EventDispatcher | |
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the primitive value of the specified object. | Object | |
![]() |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Events
Event | Summary | Defined By | ||
---|---|---|---|---|
![]() | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | ||
![]() | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher |
Property Detail
Constructor Detail
Method Detail
Event Detail
Examples How to use this example
DataProviderExample.as
This example demonstrates how data providers can be used to maintain the contents of several data grids.
To run the example, follow these steps:
- Add the Label, Button, ComboBox, TextInput, and DataGrid components to the library.
- Save this code as DataProviderExample.as in the same directory as your FLA file.
- Set the Document class in the FLA file to DataProviderExample.
package { import fl.controls.Button; import fl.controls.ComboBox; import fl.controls.DataGrid; import fl.controls.Label; import fl.controls.TextInput; import fl.data.DataProvider; import flash.display.Sprite; import flash.events.*; import flash.text.TextFieldAutoSize; public class DataProviderExample extends Sprite { private var southern:DataGrid; private var northern:DataGrid; private var world:DataGrid; private var southernRoster:DataProvider; private var northernRoster:DataProvider; private var leagueCB:ComboBox; private var nameTI:TextInput; private var goalsTI:TextInput; private var submitBtn:Button; public function DataProviderExample() { southernRoster = new DataProvider(); northernRoster = new DataProvider(); createDataGrids(); createUI(); } private function createUI():void { var description:Label = new Label(); description.text = "Enter player's name, goals scored, and hemisphere of origin:"; description.autoSize = TextFieldAutoSize.LEFT; nameTI = new TextInput(); goalsTI = new TextInput(); var submitBtn:Button = new Button(); submitBtn.label = "Submit Player"; submitBtn.addEventListener(MouseEvent.CLICK, submitPlayer); leagueCB = new ComboBox(); leagueCB.addItem( { label:"Northern", data: 0 } ); leagueCB.addItem( { label:"Southern", data: 1 } ); description.move(10,10); nameTI.move(10,40); nameTI.setSize(150,24); goalsTI.move(170,40); goalsTI.setSize(40,24); leagueCB.move(220,40); leagueCB.setSize(120,24); submitBtn.move(350,40); goalsTI.restrict = "0123456789"; addChild(description); addChild(leagueCB); addChild(submitBtn); addChild(nameTI); addChild(goalsTI); } private function submitPlayer(e:MouseEvent):void { if(nameTI.text != "" && goalsTI.text != "") { var targetRoster:DataProvider; if(leagueCB.selectedItem.label == "Southern") { targetRoster = southernRoster; } else { targetRoster = northernRoster; } targetRoster.addItem( { Name: nameTI.text, Goals: goalsTI.text } ); var worldRoster:DataProvider = southernRoster.clone(); worldRoster.merge(northernRoster); worldRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING); southernRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING); northernRoster.sortOn("Goals", Array.NUMERIC | Array.DESCENDING); world.dataProvider = worldRoster; nameTI.text = ""; goalsTI.text = ""; } } private function createDataGrids():void { southern = new DataGrid(); northern = new DataGrid(); world = new DataGrid(); southern.move(10,100); northern.move(180,100); world.move(350,100); southern.setSize(170, 250); northern.setSize(170, 250); world.setSize(170, 250); southern.columns = northern.columns = world.columns = [ "Name", "Goals" ]; southern.dataProvider = southernRoster; northern.dataProvider = northernRoster; addChild(southern); addChild(northern); addChild(world); var northernLabel:Label = new Label(); northernLabel.autoSize = TextFieldAutoSize.LEFT; northernLabel.text = "Southern Hemisphere"; northernLabel.move(10,75); addChild(northernLabel); var southernLabel:Label = new Label(); southernLabel.autoSize = TextFieldAutoSize.LEFT; southernLabel.text = "Northern Hemisphere"; southernLabel.move(180,75); addChild(southernLabel); var majorLabel:Label = new Label(); majorLabel.autoSize = TextFieldAutoSize.LEFT; majorLabel.text = "World"; majorLabel.move(350,75); addChild(majorLabel); } } }
Wed Nov 21 2018, 06:34 AM -08:00