Using in-memory databases in AIR

Jacob Wright
May 16th, 2008

Adobe Integrated Runtime (AIR) has support for creating and using SQLite databases through the use of the SQLConnection class in the flash.data package. Using this package you can store a database on a user's hard drive and even name it with any extension you'd like (registering your app with that extension will let you double click on your "database" file and open the app with that as a parameter, pretty slick).

One feature with the database package often overlooked is its ability to create and use in-memory databases. Using in-memory databases allows for faster read and write to the database and is perfect for operations such as building a code-completion lookup (someone going to rewrite Flex Builder in AIR? :), establishing a temporary search database of all the words in a list of documents that could be used for an autocomplete field, and any other situation where a database would be great to use but doesn't need to be kept around between application launches.

To create an in-memory database simply leave out the file parameter of the database connection.

var db:SQLConnection = new SQLConnection();
db.open(); // no file is passed in

Then you run your database setup script to create your tables and your good to go.

AIR ActiveRecord is Open Source

Jacob Wright
April 29th, 2008

I wrote about an Active Record implementation for the Adobe Integrated Runtime using it's SQLite database functionality. I put up all the code on Google Code under the name AIR Active Record. Please check it out, let me know of bugs or features, or better yet, submit fixes and add-ons. If you're interested in being an active developer on it let me know.

Why Open Source

Jacob Wright
April 3rd, 2008

I have to admit, it took me awhile to understand why anyone would want to open source their software. I understood perfectly well why I would want to use it, but as a developer who makes money from writing software I assumed you don't make money writing open source software, thus, you starve. I understand now how it works and will explain simply for both developers and business why open source software makes sense.

(more...)

Don’t use Number to iterate over for-loops

Jacob Wright
March 18th, 2008

A while back I read a couple of blog posts about the slowness of using uint and int to iterate through for-loops. I needed to do some testing for a little project today and found this is false.

When using the "i" variable in for(var i = 0; i < length; i++) as an input into mathematical operation, especially when doing fractions, Number is faster for obvious reasons. This was established in the posts of the previously mentioned blogs. But when simply iterating over an array which is a very common use-case for for-loops uint is faster. Here is my test setup:

var value:Object;
var arr:Array = new Array(1000000);
var length:uint = arr.length;
var startTime:Number = getTimer();

for (var i:uint = 0; i < length; i++)
value = arr[i];

var endTime:Number = getTimer();
trace("Total Time:", endTime - startTime);

I was getting around 210 for uints and around 230 for Number. Not a big difference, but I feel dumb for always using Number for this sort of thing without even thinking about how it works.

Using Your Own Custom Metadata in AS3

Jacob Wright
March 15th, 2008

Flex 3 gives us a great new feature, custom metadata tags. Now, I know you could actually use custom metadata in Flex 2, but you would have to add "-keep-as3-metadata MyTag" to every single project that utilized these custom tags. In Flex 3, if you add "-keep-as3-metadata MyTag" to a library (using compc to compile a SWC or a Flex Builder Library project), then EVERY project that uses that SWC will automatically keep the "MyTag" metadata tags. This allows custom libraries that utilize these tags for development.

Would be cool to create a library to hook up listeners so you can create listeners like this:

[Listen(obj="this.closeButton", event="click")]
public function closeClickHandler(event:MouseEvent) {...}

You'd use -keep-as3-metadata Listen in the libraries compiler options. Maybe if you want I could post a tutorial on doing something like this. Drop me note and let me know if there is interest.

Why is WordPress so easy to install, so painful to update?

Jacob Wright
March 14th, 2008

I don't think there is a better open-source blog engine on the market than WordPress, but why is it so painful to update it? You have to back up the database, download the files, copy over the config file, themes, uploads, and any other stuff you need to the new installation, and then rename the folders quickly so the new one fills the space of the old one.

Why can't we just get the files that have changed downloaded and the database updated by pressing a big blue "Update" button?

Next Page »