Categories
Programming

WeightManDesktop, an AIR application for Weightman (iTunes)

WDM-r2

Here’s a small application called WeightManDesktop that I wrote as a proof of concept to see how difficult it was to import a csv file and process it in actionscript. I blogged about it earlier here.

It uses the csv file that is generated by WeightMan (iTunes link), a free iPhone program that allows you to note your weight over time intervals. Weightman allows you to export your entries in csv and sent them by mail to your desktop. I wanted a desktop application that could display all the entries in one go.

The iPhone app is made by Katachi studios. I did try to contact them to let them know I was posting this, but as their site is partly in japanese and there is only a small english page, I couldn’t find the contact email… [update: I managed to contact them, and they seem happy with it 🙂 ]

To use the program, use the install badge below – it’s an AIR application, so you need to first install the run-time air player as well if you haven’t done so before. I’ll make a proper install badge for it sometime in the future if or when I revise the program.

Use the source button on the bottom of the screen to locate the csv file and import it. Two graphs will then be shown, one showing your weight and one showing your body mass index level, as calculated by Weightman.  There’s a toggle button to show only the last 30 entries as well.

It’s a very basic first release, but I may add additional functionality it in the future. If you would like an improvement or see something to fix, please leave a comment.

[Update: link changed to point to version 0.2 – changes are described here]

[airbadge] WeightManDesktop, https://boschmans.net/wp-content/uploads/2009/11/WeightManDesktop.air, 0.2, https://boschmans.net/wp-content/uploads/2009/11/WDM-r2.png[/airbadge]

Categories
Hardware

EyeTV Elgato USB Device 1.1 error

EyeTV 3 is complaining when I plug in the Elgato EyeTV Hybrid device that my USB port is 1.1 and it’s needs a 2.0 device to operate.

Apparently this is a common problem for Elgato EyeTV hybrid devices, although EyeTV wants it to be called a ‘rare’ problem.

But! The fix is here! Apparently for most devices, you just have to ‘cook’ it. In other words, to (temporarely) get it working again, you need to get it warm again.

Several solutions have been proposed in this Elgato support forum, and I won’t keep you from a few:

  • stick the usb ‘stick’ between your chair and your bottom for a few minutes
  • put it in the oven for a few seconds or minutes on low temps (I would NOT recommend this)
  • put it on an external harddrive that gets hot (like for example, oooeh I don’t know, an Apple TimeCapsule ?)

Anyway, after warming it a bit on my TimeCapsule, it worked like a charm ! Elgato recognises the device again, and since my iMac hardly ever shuts down, this should keep going until the next reboot or so.

Categories
Programming

Reading and Displaying a csv file using Flex (AIR) and Actionscript

I’ve already written a python script that can convert a .csv file to a .xml file, which quite a few people seem to like. This is a good solution when you have a large file to convert.

But really, reading a small and simple csv file directly into Flex/Flash to use it in charts or display the contents in a DataGrid would be a “Nice To Have” solution. Plus, I’ve noticed that over the years I reuse my code and each time I add new functionality to it; now is the time to start with it !

So I made an AIR application ( for the simple reason that I load a local csv file) that does exactly that. The AIR app is called WeightManDesktop.

Since I know it’s a small file that I’m loading, it doesn’t matter that I load it completely into memory. For a larger file, in Python I would typically open the file for reading and read it line by line, processing each line as I go.

Using the File.browseForOpen AIR functionality, I read in the file selected by the user into a string and then process the content in a seperate function:

// Read in the selected file when the file is selected
private function openfileSRCHandler(event:Event):void{
fileStream.open(file, FileMode.READ);
content = String(fileStream.readUTFBytes(fileStream.bytesAvailable));
fileStream.close();
trace(“*** File loaded.”);
processContent();
}

Using the strings split function, I first split the string into seperate lines using the line seperator to split them. Each line thus becomes an Array. I then split each line into seperate content, again using the split function using commas to seperate them into the seperate items. These items are then added to an ArrayCollection that I’ve previously defined.

private function processContent():void {
//var ending:String = new String(“\n\g”);
// Split the whole file into lines
var values:Array;
var lines:Array = content.split(“\n”);
trace (“File split into ” + lines.length + ” lines”);
// Split each line into data content – start from 1 instead of 0 as this is a header line.
for ( var i: Number=1; i < lines.length; i++ ) {
var line: String = lines[i];
values = line.split(“,”);
trace (“line split in ” + values);

// Add values to arraycollection
linedata.addItem({date:values[0], weight:values[1], bmi:values[2], workout:values[3]});

And that’s it. Use the ArrayCollection as a dataprovider for your datagrid and Bob’s your Uncle !

Categories
Programming

Creating Via FlexBuilder Design View Is Easy !

In my current wrestling with programming my CatchaTrain application (ahem! A spiffy sounding application name) I have normally only one main state (in other words, a particular view of my application) that shows the hour that the next train is leaving.

Somehow however I have now managed to create in my main application 4 additional states (actualy 5, but the first one will disappear in due time) :

  • Initial state which is shown when you start up the application for the first time: it asks you to select a station –> this needs to be removed and changed to initial empty train view!!
  • Train leaving in … hours and minutes view
  • Dropdown showing a datagrid of the leaving time of your train from that station
  • Overlay state showing you buttons to add a station or add a train
  • Overlay state for actually adding the station
  • Overlay state for actually adding a train

It all works fairly logically, and I am quite happy with the results. But really, unless I had FlexBuilder, I wouldn’t be able to make heads or tails out of the different states. Many is the time that I switch to design view to check a state, add a button or remove a textfield.

If there’s one thing that flexbuilder does well, it’s that you can check via the designer view if what you are doing actually makes sense.

Now, on with the code… I’m almost finished (I’ve been saying that for the last 2 months or so…)

Categories
Blog News Programming

flex error 1180: Call to a possibly undefined method SortField.

Here I was, following a very nice tutorial showing you how to use an XMLListCollection with a nice example with source view enabled (thank you Bruce Phillips, btw!) when suddenly flexbuilder starts to complain about error 1180 : Call to a possibly undefined method Sortfield.

Even when the sortfield function is right there in the same function !?

It turns out, after quite a bit of googling around finding not very much, that flexbuilder for once did *not* automagically write the import statement for the sortfield. It did so for the sort function, but not for the sortfield function. I don’t know if this only happened to me or if this is so all the time.

But here, the advantage of working with flexbuilder turned to a disadvantage – I expected it to add the import statement necessary for it all by itself; for once, it did not do it.

All I needed to do was to add the  import mx.collections.SortField; to get things working again. Still, I lost some programming time looking for a solution to this problem, so I’m blogging this in case you have a similar experience.

Categories
Programming

Counting the number of elements in an XMLList : Actionscript and Python are more alike than I thought.

I just realized that ActionScript 3.0 and Python are more alike than I thought.

When I started programming my very very first program in MXML and ActionScript (not too long ago, actually), I had written a nice and short function that counts the number of elements in an XMLList variable, of which I was very proud. After all, it worked !

// Function to count all elements and return the total count in a given XMLList
// Warning : using XML will return always 1, use XMLList instead
private function countElements(list:XMLList):int{
var counter:int = 0;
for each (var prop:XML in list){
counter += 1;
}
return counter;

When all I *really* needed was to state

// Duh!
var counter:int = XMLfile.length();

I should have known something like this existed ! Python has similar ‘methods’ available, although for a list they are called as function ‘len’ :

counter = len(list)

Oh well, live and learn.

Categories
Programming

When your flex test build suddenly no longer works

When I’m using Adobe Flex to run a test build of my application, often for testing a change I just made, I sometimes get an error, on which I click continue, and then instead of continuing, nothing else happens. This usually happens because of a run-time error.

Subsequently, Flex builder still works, but any release builds you want to create no longer get made; nothing shows up as an error.

I’ve found out that the probable culprit is the adl compiler, which is stuck, most probably waiting for input which you cannot supply.

The easiest way to get out of this situation is to use taskmanager to kill the adl process. This allows flex builder to run test builds again. However, the source that causes the problem is in the programming change you made, so you need to solve that first otherwise it will again create the same situation, and then you need to kill adl again…

Categories
Programming

Aarghl! Error #1034 Type Coercion failed: Cannot convert something to something

The error “Type Coercion failed: cannot convert [#78F6AA, #CAF2DA] to Array” has stared me in the face for the past few days or so.

The error actually has useful information in it (but at the moment I got it, ofcourse I never properly read it…). It states that whatever you are doing, you are passing the wrong type of variable to the function/variable. It expects it to be in another type.

This blog entry helped me to understand the error message.

I wanted to implement a function so the user can select his own gradient colors and save them as a preference for my AIR app. cp1 and cp2 are 2 flex colorpicker functions.




[Bindable] private var colors_selected:Array = [cp1.selectedColor, cp2.selectedColor];

However, everytime I ran the program I got the Type Coercion error.

Finally I found out what’s wrong. I made an array out of both colorpicker selected colors, and then passed it to backgroundGradientColors in another array.
Duh (Smacks head) !
Of course it doesn’t like it ! Below is the corrected code. The mx:SetStyle now does not specify an array, as this is constructed in the variable colors_selected.




[Bindable] private var colors_selected:Array = [cp1.selectedColor, cp2.selectedColor];

Categories
Blog News

Squid: oktapodi

You can find more information about this movie on it’s official website.

Categories
Programming

When is the next train leaving ? (Flex application)

I’ve created a smallish new AIR program called “TrainDeparture”, but as it currently uses no database except an xml file, it was fairly easy to recompile it for the web. It has ‘view code’ enabled, by the way.

The program does one thing only : based on the current time it checks the xml file for trains (that you will, for now, need to create yourself or edit the one I supply via a text editor) and will show you the time of the next train leaving.

You can see the results by clicking here:Train Departure

By clicking on the “Prefs” button you will see a resize of the application with a datagrid showing the current entries in the file (it’s there for reference, and in the future I want to add additional stations and more preferences in there).

The “Next” button shows you the train after that, and the one after that, etc. There’s a timer event running so after 30 seconds (or less) the time shown by the next button will be reset to the current next train.

The next thing I want to change is to show not the time the train leaves, but the minutes remaining before the train leaves – I think it will be far more useful for me to see how many minutes remain.

Should you wish to use it, I’ve described the structure of the XML file below.

It’s basically functional, but there is quite a lot of amelioration that can be made to the program. One of them is coding to show the trains on weekdays or in the weekends based on the current date. Another one is to show the remaining minutes before the train leaves.

Also a quick nod to the StackOverFlow website, where a kind person helped me solve a problem with the ‘states’ setting that was driving me crazy. It’s a website for programmers by programmers !