Time Tracker AIR Update, and what I learned about label functions and optional args in Flex

I’ve got a big update to the my little Time Tracker AIR application, thanks mostly to Kyle Hayes. He gave some UI loving to the app - see below:

I’ve done a bit more cleanup. One of the things I fixed was my duplicate labelFormatter. The labelFunction feature is one of the neatest things in Flex. When it comes to a control that takes a set of data, you can say, “When displaying X, call this function.” Your function can then do stuff like, “If the row of data has a price more than 100, mark it (Expensive!)”. You get the idea. What was bugging me though was that I wanted to use the same labelFunction for my DataGrid and my ComboBox. But the DataGrid passes 2 arguments to it’s label function, and the ComboBox passes one. I wrote two functions which both did the exact same thing. Turns out (and I found this online but forgot to bookmark where) there is a simpler solution - just mark the section argument as optional. Here is an example from my code:

private function projectLabel(item:Object,col:DataGridColumn=null):String { return item.project + " (" + item.client + ")"; }

In this code block, the second column has an optional value. It is optional because we define a default value to use in case one isn’t passed.

Anyway, most of my changes are pretty small. I switched to using States to handle “loading” versus ‘real’ application. I also made the Hour panel notice if you have no active projects. (Need to double check that I have the active flag in there.)

I’m still struggling with the dates though, and I’ve had some folks help me out on my other post, so hopefully that will get corrected soon.

So now I’m going to turn my attention to a reports page. I’ve only played with Flex charts a bit, but I’m looking forward to it. I’d especially love to be able to find out which client/project paid me the most money, something that isn’t possible with the current system I use.

I know I keep saying the following, but I should repeat it anyway. I’m really loving AIR and Flex. But please consider my code to be anything but best practice.<p>Download attached file.</p>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments