I went through the tutorials on flash-creations.com in regards to server communiction (loadvars vs amfphp remoting). I chose to go the amfphp route, but I am running into some problems. When I display data from a database through the datagrid component, I am able to sort columns asscending (via actionscript)...but they won't sort back to descending.
Also, using the above tutorials...its seems that in the amfphp tutorial the scores column is being read and sorted as strings although they should be numbers. Why is that?
Thanks Much!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have experienced this type of problem in the past as well, and I can't remember exactly what fixed it but it was really really simple if I remember correctly. Let me take a look at it over the next few days and I'll get back to you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Patrick. The solution to this would help my project out tremendously! Otherwise I'll have to go the Loadvars route and I really don't want to do that. Hope to hear from you soon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The tutorial works very well except for one issue with the header sorting. The usual 'patch' applied on datagrids for numeric sorting won't work here because in fact DataProvider.sortItemsBy and RecordSet.sortItemsBy has a different signature. That is why it was working when the dataProvider was a vanilla array (in the LoadVars case) and not in the RecordSet case. This is not an amfphp errorbut rather an inconsistency in MM's v2 API. That one took me a good hour to track down.
function sortNumerically(evtObj)
{
var i = evtObj.columnIndex;
var col = scores_dg.getColumnAt(i);
if(i == 1)
{
//Sort this column numerically
var dir = col.headerCell.asc ? 2 : 0;
scores_dg.dataProvider.sortItemsBy(col.columnName, null, dir | Array.NUMERIC );
col.headerCell.asc = !col.headerCell.asc;
}
}
Here is a zip with the fla, the php class and the sql:
www.5etdemi.com/uploads/highscores.zip
I remember a Technote saying that to solve this issue you had to use all sorts of dataBinding voodoo, when in fact probably all it did is convert the RecordSet object to a vanilla array.
Note: when using the mx v2 components, Array.prototype is mixed in with mx.controls.listclasses.DataProvider and therefore acquires a whole bunch of new methods. It makes arrays dispatch events and do all sorts of voodoo. That is one of the reasons why apps with v2 components are slowed down. Mixins are kind of cool (EventDispatcher is great) but mixing-in the prototype of one of the core objects with all sorts of stuff should be considered evil.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I went through the tutorials on flash-creations.com in regards to server communiction (loadvars vs amfphp remoting). I chose to go the amfphp route, but I am running into some problems. When I display data from a database through the datagrid component, I am able to sort columns asscending (via actionscript)...but they won't sort back to descending.
The tutorial ( http://flash-creations.com/notes/servercom...ting_amfphp.php )uses the exact same code as the load vars tutorial ( http://flash-creations.com/notes/servercomm_database.php ) in regards to sorting, but the amfphp example won't sort columns both ways (asc and desc). What am I missing. Please help! How does amfphp handle sorting differently? What would be the correct actionscript?
Also, using the above tutorials...its seems that in the amfphp tutorial the scores column is being read and sorted as strings although they should be numbers. Why is that?
Thanks Much!
I have experienced this type of problem in the past as well, and I can't remember exactly what fixed it but it was really really simple if I remember correctly. Let me take a look at it over the next few days and I'll get back to you.
Thanks Patrick. The solution to this would help my project out tremendously! Otherwise I'll have to go the Loadvars route and I really don't want to do that. Hope to hear from you soon.
The tutorial works very well except for one issue with the header sorting. The usual 'patch' applied on datagrids for numeric sorting won't work here because in fact DataProvider.sortItemsBy and RecordSet.sortItemsBy has a different signature. That is why it was working when the dataProvider was a vanilla array (in the LoadVars case) and not in the RecordSet case. This is not an amfphp errorbut rather an inconsistency in MM's v2 API. That one took me a good hour to track down.
Here's the fix:
in onGetScores:
scores_dg.getColumnAt(1).sortOnHeaderRelease = false;
scores_dg.addEventListener("headerRelease", Delegate.create(this, sortNumerically));
Then the sortNumerically function:
function sortNumerically(evtObj)
{
var i = evtObj.columnIndex;
var col = scores_dg.getColumnAt(i);
if(i == 1)
{
//Sort this column numerically
var dir = col.headerCell.asc ? 2 : 0;
scores_dg.dataProvider.sortItemsBy(col.columnName, null, dir | Array.NUMERIC );
col.headerCell.asc = !col.headerCell.asc;
}
}
Here is a zip with the fla, the php class and the sql:
www.5etdemi.com/uploads/highscores.zip
I remember a Technote saying that to solve this issue you had to use all sorts of dataBinding voodoo, when in fact probably all it did is convert the RecordSet object to a vanilla array.
Note: when using the mx v2 components, Array.prototype is mixed in with mx.controls.listclasses.DataProvider and therefore acquires a whole bunch of new methods. It makes arrays dispatch events and do all sorts of voodoo. That is one of the reasons why apps with v2 components are slowed down. Mixins are kind of cool (EventDispatcher is great) but mixing-in the prototype of one of the core objects with all sorts of stuff should be considered evil.
Thanks a lot Patrick!