Link to home
Start Free TrialLog in
Avatar of NewAS
NewAS

asked on

LoadVars - ASP to Flash Array

I have created a simple DataGrid and I am using the code below:

var content_lv:LoadVars = new LoadVars();
content_lv.onLoad = function(success:Boolean) {
if (success) {
UserGrid.addColumn("Title");
UserGrid.dataProvider = content_lv.myGrid;
}
};

var fetch_content_lv:LoadVars = new LoadVars();
fetch_content_lv.name = content_t.text;
fetch_content_lv.sendAndLoad("http://mydomain.com/search.asp?unitID=1&searchTV=book", content_lv, "POST");

My sample asp output looks like this:

myGrid={ID:"274", Title:"Book+1"},{ID:"275", Title:"Book+2"}

This output is the same as if I just cut and pasted the sample asp output and pasted like so into my actionsript:

var content_lv:LoadVars = new LoadVars();
content_lv.onLoad = function(success:Boolean) {
if (success) {
UserGrid.addColumn("Title");
books = new Array(
{ID:"274", Title:"Book+1"},{ID:"275", Title:"Book+2"}
);
UserGrid.dataProvider = books;
}
};

var fetch_content_lv:LoadVars = new LoadVars();
fetch_content_lv.name = content_t.text;
fetch_content_lv.sendAndLoad("http://mydomain.com/search.asp?unitID=1&searchTV=book", content_lv, "POST");

Obviously the cut and past isn't actually using the asp feed but it works and I think it is down to the use of quotes.

Does anyone know how to parse the ASP output to a Flash array to dynamically generate the DataGrid content?

Any help would be much appreciated.
Avatar of NewAS
NewAS

ASKER

We have a winner:

var content_lv:LoadVars = new LoadVars();
content_lv.onLoad = function(success:Boolean) {
      if (success) {
            for (var i = 1; i<=31; i++) {
                  mydatagrid.addItem({ID:this["ID"+i],Title:this["Title"+i]})
            };
      };
};
var fetch_content_lv:LoadVars = new LoadVars();
fetch_content_lv.name = content_t.text;
fetch_content_lv.sendAndLoad("http://mydomain.com/search.asp?unitID=1&searchTV=book", content_lv, "POST");

var userListener = new Object();
userListener.change = function(event) {
      trace(
              "This ID: " + event.target.selectedItem.ID +
              " and the Title is: " + event.target.selectedItem.Title
             );
};
      
mydatagrid.addEventListener("change", userListener);

My sample ASP code:

If gObjRs.BOF and gObjRs.EOF Then
Else
      Dim intRec, dataGrid

      For intRec=1 To gObjRs.RecordCount
            If Not gObjRs.EOF Then
                  dataGrid = dataGrid & "&ID" & intRec & "=" & gObjRs("book_ID") & "&Title" & intRec & "=" & gObjRs("book_title_TV") & ""
            gObjRs.MoveNext
            End If
      Next
End If

Response.Write (dataGrid)

The above works like a charm, yippee.

Regards, NewAS.
ASKER CERTIFIED SOLUTION
Avatar of EE_AutoDeleter
EE_AutoDeleter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial