Categories
Apple Programming

WeightManDesktop v.0.2 (AIR)

WDM-r2

I updated my little AIR application called WeightManDesktop (which uses data from WeightMan, a free  iPhone application made by Katachi Studios) to version 0.2.

Changes in version 0.2:

  • Calculates the minimum and maximum weight
  • Calculates the minimum BMI
  • Both the weight graph and the BMI graph now don’t start from 0 – instead they use the minimum values to calculate the begin value of the graph
  • The graphs are much more clear now and the changes in weight show up more distinctly.

You can download version 0.2  of the program by clicking on the install badge. Version 0.1 entry and description can be found 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
Programming

AWStats Tool that creates custom IIS log format lines

I recently ran into a problem where I needed to read a few IIS logs to find out the number of visits during the day. The tool I wanted to use was AWStats, a  free log file analyzer tool that can create some handy reports.

If you need to read an IIS log file where the admin has set up a custom log method, this tool for AWStats is very handy: in the top of your IIS log file it states which are the variables it uses. By selecting these on the web page, you get a custom awstat log format line that you can just copy / paste into your awstat config lines.

Categories
Programming

Adobe Flash Builder 4 (beta)

I found a great site for an introduction to the new Flash Builder 4 that’s still in beta. It has finally convinced me that there is enough difference between Flexbuilder version 3 and Flash Builder 4 that it’s worth it to spend some time *now* with it than when it is coming out (whenever that will be).

The wiki site is called “Learn Flex 4 from Scratch” and is being written (so it’s not finished yet) by an Adobe community manager who is documenting his own strides in re-learning Flex.

If you want to follow it, you need to download Flash Builder 4 beta 2 – and you need an existing Flex Builder serial number if you want to use it more than the default 60 days.

Categories
Programming

Local swf file with networking workaround: use Mini-Server (Windows)

Mini-Server_1

Recently  I created a small app to show off in a demo. It’s supposed to live on a webserver, and loads an xml file which contains urllinks using an HTTPService, and then assigns these links to buttons in a tabbed navigator flash component that’s located somewhere in the html page.

For the demo, I created a few dummy html pages that are kept in the same directory and pointed the urls in the xml to use those.

The problem I faced was that I didn’t have a handy webserver to store my release build on when I wanted to demo the app – when I started it up using Windows File Explorer, double clicking the bin-release html file, Flash decided to put it in a mixed sandbox security mode: local-with-network, which means that you forfeit local access to other files. And so my app suddenly couldn’t find it’s xml file anymore. And the purpose of the app is to put it up on a website, the local execute was just to demo to app.

[When you run your app inside the FlexBuilder program, by the way, this all works fine without any problems – it’s only when you do a release build that you suddenly start to learn about security sandboxes and apps with local or networking rights.]

I didn’t fancy writing a server in Python/CherryPy. Although quite possible,  it would take time, and I wanted a solution right then and there. It needed to be portable, and smallish, and as long as it could serve some static pages with client-executed content in it I would be happy.

Enter Mini-Server, which is completely standalone program, vintage 2006, about 462K, and does the job admirably. If you install PHP and show it where it lives it can even do php pages. It’s made by John Owen, which apparently is a nom de plume for a whole rafter of bitmonkeys who churn out one program after another… 🙂

Anyway, the problem is now solved: I start the mini-server, specify the port and root folder (only once, an ini file is saved for the next time), and hit run. I can then show off my demo site with a flash app that is served via http. Once the demo is done, I hit the stop button. It all fits on a usb stick, neat !

Please note that this is a small server for development purposes only. The author notes this as well, and it’s not something  I would stick on the intarnet without extensively testing it’s capabilities/security issues. But it is still a neat program to have on your usb stick when you rapido need a webserver!

Another solution is, on compile-time, using the flex-compiler publish setting to indicate the sandbox you want your application to be in. A user can then trust the flash app and it can then use both local and networking links. See the above Adobe link in the text for more details if you are looking for that solution.

Categories
Programming

Adobe Flex 4 or Flash CS5 To Be Used To Develop iPhone Applicaitons

Adobe is hard at work on giving developers the means to create iPhone application using Flash or Flex :

– how to develop iPhone applications using Flash CS5

– using Slider and Flex 4 to create iPhone applications

– Applications for iPhone Developer FAQ

While there are no public beta builds out as far as I know (the first one, Flash CS5 is promised for end 2009), this is exciting news for all of us using Flex or Flash to create applications !

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
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.