PDA

View Full Version : database filling an ArrayCollection


tazboy
08-12-2008, 07:00 AM
How do I fill an ArrayCollection from a local database? I can get the info from a database but I'm not sure how to populate the AC. Right now I've got:

private function selectAllPlayers():void{
var sqlText:String = "SELECT * FROM Players";
selectAllSQL = new SQLStatement();
selectAllSQL.sqlConnection = conn;
selectAllSQL.addEventListener(SQLEvent.RESULT, selectAllPlayersResult);
selectAllSQL.addEventListener(SQLErrorEvent.ERROR, errorHandler);
selectAllSQL.text = sqlText;
selectAllSQL.execute();
}
private function selectAllPlayersResult(event:SQLEvent):void{
var result:SQLResult = selectAllSQL.getResult();
// AC = result.data?
grid_qb.dataProvider = result.data;
}

I know that ArrayCollections have .itemAddAt and .itemAdd . Do I use these?

Thanks for any ideas you guys have. It's appreciated.

nakedkafka
08-12-2008, 01:42 PM
this my suggestion, seems pretty simple unless you have some other ideas about this.

private function selectAllPlayersResult(event:SQLEvent):void
{
var result:SQLResult = selectAllSQL.getResult();

for each(var obj:Object in result.data)
AC.addItem(obj);

}
(AC being your ArrayCollection)

tazboy
08-14-2008, 04:45 AM
I tried doing what you suggested. It didn't work out. Maybe it has something to do with my arraycollection having to be filled with "label:" label. I also tried this:
This is what it needs to be filled with

[Bindable]
public var OffPlayersCombo:ArrayCollection = new ArrayCollection(
[ {label:"All"},
{label:"QB"},
{label:"RB"},
{label:"WR"}, ]);

Here is what i'm trying

[Bindable]
public var RbWrAC:ArrayCollection = new ArrayCollection();

private function selectAllPlayersResult(event:SQLEvent):void{
var result:SQLResult = selectAllSQL.getResult();
for each(var obj:Object in result.data);
var label:String = "label:" + '"' + obj + '"';
RbWrAC.addItem(label);
}
The [Bindable] tag makes it so if I press a button it should update a comboBox that uses that array as its dataProvider, correct?

tazboy
08-14-2008, 06:38 AM
ok, my idea is not correct. Looks like a label: is automatically thrown in there. The code that nakedkafka gave me gives me a comboBox filled with [object][Object] values. Can't seem to get rid of that.
Any other ideas?

Thanks for the help.

nakedkafka
08-14-2008, 10:26 AM
perhaps should be something like:


private function selectAllPlayersResult(event:SQLEvent):void{
var result:SQLResult = selectAllSQL.getResult();
for each(var obj:Object in result.data);
var label:String = "label:" + '"' + obj + '"';
RbWrAC.addItem({label : obj});
}

which should create an Object ({}) with key name "label" and assign it's value: obj.
?

tazboy
08-14-2008, 02:24 PM
No luck there either. I get this error when I run the program:

TypeError: Error #1009: Cannot access a property or method of a null object reference.