Wednesday, June 07, 2006

A Better GUI

The code for openIGOR's graphical user interface was such a mess of spaghetti code (in Actionscript) that I almost chucked it and started over. In my defence, it was the first real program I had written in that language. But still. Using the same event handler to service calls from different events is a BAD idea. I have now recoded just about everything. Global variables now look like global.variable, and each call to the CGI interface that talks to the database now has its own object and its own handler. The only problem I wasn't able to solve is this one:

When an onLoad handler is called, it's because some server-side code has returned interesting data for it to look at. A lot of the time that means we need to go to another frame (change pages). But I'd also like to delete the object, since it's no longer needed. So you could do:

object.onLoad = function() { // runs when data loaded
gotoAndPlay("anotherPage");
}

or

object.onLoad = function() { // runs when data loaded
delete object;
}

You can't do both, because if it runs another page it won't see the delete command, and alternatively if it deletes the object there won't be anything left to run the gotoAndPlay. So I'm going to have to trust the garbage collection to clean it up. I know there are message handlers in ActionScript 2.0, which would solve this problem, but I didn't think it was worth the overhead to add that code.

0 Comments:

Post a Comment

<< Home