Copy link to clipboard
Copied
Hi
Just a small area of dataProvider code I am 5% unsure of.
When you populate a provider with an object, eg...
myData = JSON.parse(event.target.data);// add JSON to object
listDP = new DataProvider(myData);// add object to dataProvider
data_grid.dataProvider = listDP;//set datagrid's dataProvider
...when you are making edits to the data, do you edit myData, and then to update the dataProvider...
listDP = new DataProvider(myData);// update dataProvider
...or do you somehow edit listDP directly?
Another way to ask...
...if the above was in an editable datagrid, when you make an edit, does Flash update myData, then do listDP = new DataProvider(myData); , or does it directly edit listDP?
Thanks guys
the dataProvider property of your datagrid will update so you would use:
listDP=data_grid.dataProvidier
to update listDP (which does not save json data anywhere).
Copy link to clipboard
Copied
the dataProvider property of your datagrid will update so you would use:
listDP=data_grid.dataProvidier
to update listDP (which does not save json data anywhere).
Copy link to clipboard
Copied
Thanks kGlad
What if I'm not editing in the datagrid, but programatically adding data to it (from an external source)...
Example set up:
myData = JSON.parse(event.target.data);// add JSON to object
listDP = new DataProvider(myData);// add object to dataProvider
data_grid.dataProvider = listDP;//set datagrid's dataProvider
...and then I get some external data that needs to be added, do I add it to myData, or listDP? Currently I'm adding it to myData, then re-adding the line listDP = new DataProvider(myData); to update the datagrid. Should I just be adding the data directly to listDP, and not myData?
Copy link to clipboard
Copied
you could do that, you could add data directly to listDP and you could add the data directly to data_grid.
i would use one of the latter two because i don't like creating new objects unless necessary. you're not creating a potential memory problem with that because you use the same variable (listDP) but you will be adding additional (over the latter two methods) work for garbage collection. but i don't foresee a performance problem creating new listDP objects unless you're doing that frequently.
Copy link to clipboard
Copied
I'm still confused mate.
myData = JSON.parse(event.target.data);// add JSON to myData array
listDP = new DataProvider(myData);// add array to dataProvider
data_grid.dataProvider = listDP;//set datagrid's dataProvider
Now when I try to access the dataProvider like...
trace(listDP[0].keyName);
...I get 'Property 0 not found on fl.data.DataProvider'
If I populated listDP with an array, and want to directly edit listDP, why does listDP[0] throw an error? Isn't the dataProvider an array?
Copy link to clipboard
Copied
a dataprovider is not an array. it doesn't have array methods. even if you used an array to define a dataprovider (which you did not), you can't use array methods.
use the dataprovider methods like getItemAt:
trace(listDP.getItemAt(0).keyName)
Copy link to clipboard
Copied
That just opened up a whole world for me. Thanks kGlad!!!
Copy link to clipboard
Copied
you're welcome.
p.s. use the adobe help files. the as3 class reference file contains a wealth of information.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now