Day by day

I’ve just finished the interface for browsing the work day by day. It took much more time then anticipated. This was because as soon as I jumped to another day the program started slowing down to an unacceptable level. I had to figure out why that happened before I could carry on. Finding that out and fixing it took me aboutĀ five hours!

I finally discovered that a drawing new heart-beat graph slowed down the program because it got bigger with every new day you clicked. This graph is build up from thousands of dots and lines. To make the animation go faster I had to remove those first. But I put them in the wrong place so I couldn’t remove them. I had to rewrite the code for building the graph so I knew where all the lines and dots were and then I could remove them. Now with every day you pick the old graph is removed and a new one is drawn and the speed stays the same.

On the net I found this really nice code for adding listeners to the seven buttons in a dynamic way:

addEventListener(MouseEvent.CLICK, mouse_click);
function mouse_click(event:MouseEvent):void {
var object_name=String(event.target.name);
for (var i:int = 0; i < 7; i++){
if (object_name == day_btn_array[i])
{
get_day_data(event);
}
}
}

So instead of writing all the listeners by hand I now only have three eventlisteners (only one is shown here.) With every click the function finds out what button was clicked. It calls the appropriate function and passes the original click event. In the called function I again retrieve the name of the button from that event using event.target.name again.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.