Notes on Java, Solaris, PHP, LDAP…

November 17, 2007

Adobe Flex – ActionScript language features, sorting by columns in mx:DataGrid

Filed under: Uncategorized — negev @ 8:15 pm

20 Apr 07
Notes on Action Script
1. It’s both statically & dynamically typed
If you access an object/component stored in a variable, and that variable is typed to that appropriate class, then Flex IDE gives you field/method hints as you type. So if you have var array:Array; and you type array. then it shows you a list of methods – Flex retrieves them from static type. However, even if you have a variable statically typed, Flex allows you to type and compile fields/methods which are not supported by that static type – because Flex allows dynamical typing, PHP-like.

So I can use a method/property which is not declared by the variable’s static type. However, if the actual runtime type of the variable won’t be right and there’s no such a method/property in runtime, then debug SWF fails and opens Flex in debug mode. However, live SWF quietly stops the current event without any message.

So maybe we could use a global error handler, which would catch such quiet errors in live, would send them to server and log or report them. Obviously, we don’t want to use such a handler for connectivity errors otherwise it would go recursive.

2. Objects are assigned by reference. However, Flex API getters/setters of API properties most likely use protective copies. If you store a result of a property, e.g. mx.controls.Tree’s openItems and you modify it (e.g. by calling push(..) on it) that won’t be reflected in the view, and you can see that myTree.openItems will be different to openItems copy you just modified. So after you apply any modifications, you need to save it by invoking the setter – myTree.openItems= theModifiedCopy. E.g.

var openItemsCopy:Object= groupList.adminGroupsTree.openItems; // openItems is probably of type Array, but Flex doesn’t document that.
if( openItemsCopy.indexOf(groupsNode) <0 ) {
openItemsCopy.push( groupsNode ); // This doesn’t refresh the tree; we need to set it to kick it in:
groupList.adminGroupsTree.openItems= openItemsCopy;

3. ‘for in ‘ and ‘for each in’ are quite different loops. Use ‘for in’ to iterate over Object’s field names and Array keys (indices). Use ‘for each in’ to iterate over entries (values) of Array and collections e.g. ArrayCollection.

for( var fieldName:String in myObject ) {

var fieldValue:Object= myObject[fieldName] fieldName+ “: ” +fieldValue );

for each( var entry:Object in myCollection) { entry );

19 Apr 07
Although Flex performs static type check whenever static types are known, it’s not 100%. It compiles the following, although there’s no Array.contains(*) method
var memberListEmails: Array= baseApp.memberList.memberListEmails;
if( memberListEmails.contains(myObject) ) {…}

18 April 07
Flex sorting by columns in mx:DataGrid
When using a renderer, either parameterized via an implementation of mx.core.IFactory, or non-parameterized, then it accesses data fields via Action Script. That is case-insensitive to the field name. E.g. field can be ‘fullName’ or ‘fullname’ and you get the entries rendered fine by <mx:Text xmlns:mx=”; text=”{data[field]}”

However, when trying to sort entries by such a column, you must pass it exact case-sensitive to <mx:DataGridColumn dataField=”fullname”… Otherwise sorting by that column won’t work, but entries will be still rendered.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: