Archive for December, 2003

Configuring Flash Applications with INI Files

I have seen several different techniques for configuring Flash applications. The simplest and most often used is probably the comment technique:

//var someUrl = "";
var someUrl = "";

Another technique is to use trace statements to redefine variables for a development environment, then omit the trace statements while publishing your movie in preparation for production (thereby defining the variables in a manner appropriate for production):

var someUrl = "";
trace(someUrl = "");

These methods both require you to maintain your configuration inside your application FLA file, which isn’t always convenient, especially if you want one SWF file to run two different ways in two different contexts. External configuration is more appropriate for this type of requirement. To configure your applications externally, you can use several techniques:

  • XML
  • XMLSocket
  • loadMovie
  • loadVariables
  • Probably some others I can’t think of right now

XML is a great solution, but sometimes it’s overkill, and can be more trouble than it’s worth for just a few configuration parameters. In such circumstances, I like to use external files in INI format:

# This is a comment.  It will be ignored.

For parsing external INI files, I use the PropertyLoader class (along with the SimpleMap class). So far I have had good luck putting the INI file in the same directory as the the SWF file and loading it like this:

var pLoader:PropertyLoader = new PropertyLoader();
pLoader.loadFromUrl("myConfigFile.ini", this, "onSuccess","onFailure");

public function onSuccess(params:SimpleMap):Void
trace("Just loaded "+params.size()+" properties.");

public function onFailure(msg:String):Void
trace("It didn't work because: " + msg);

What kinds of techniques do you use for configuration?

Log Levels in Flash

One of the biggest problems with ActionScript 1.0, as we all know, is the lack of both compile- and run-time validation. Make some small typo, omit a “this”, or get your scoping mixed up inside of a callback, and you’re looking at anywhere from 5 minutes to hours of hunting through your code line by line, if not character by character, trying to figure out why your application is not behaving as expected. One solution is to use ActionScript 2.0, however for those instances when 2.0 is not an option, here are some debugging tips.

Continue reading…

Regular Expressions in Central

One of my favorite parts of the Central API is the RegExp object. Here some examples from an application I’m working on right now.

The “” file:

var validUrlRE = new RegExp("^(http|https|ftp|file)://.+");
var titleRE = new RegExp("<title>(.*?)</title>");
var allAlphaNumericRE = new RegExp("^\\w+$");

Excerpts from the file that uses some of the regular expressions:

#include "util/"

if (validUrlRE.test(this.urlInput.getValue()))
// urlInput contains a mostly valid URL.

if (allAlphaNumericRE.test(this.nameInput.getValue()))
// this.nameInput contains alpha numeric characters

var title = titleRE.match(htmlSource);
trace(title[1]); // This contains the HTML file's title.

Maps for Flash (part II)

I made a post a few days ago about using a Map type object in Flash rather than associative arrays or objects, and I got some interesting comments. One person pointed out a bug in the code that I posted that keeps track of the size of the map, which was a good catch. Someone else wanted to know why I preferred a map API over objects and arrays. There are three reasons:

Continue reading…

Flex – A Third Party Perspective

You’ve probably read all there is to read about Flex on Macromedia’s site, and if you were at MAX, you heard plenty of discussion and saw plenty of demonstrations. Now check out what Java Boutique has to say about Flex.

A Map Interface For Flash

I know you can accomplish the same things with associative arrays and objects in Flash, but I’m used to Map-like interfaces, so before I could get any real work done, I had to write As it’s name implies, it’s a simple implementation which gives you put, get, remove, size, keys, values and toString functions. I prefer it over using objects and associative arrays, and it makes a good base class for building specific kinds of Maps. I haven’t written any others yet, but I can envision a SortableMap, ExpiringMap (where entries are automatically removed after a specified amount of time), ArrayMap (which automatically creates arrays for entries with duplicate keys), etc.

Be warned: this code is my own invention, and has not been QAed, so put it through its paces before incorporating it into your own project.

Messages Instead of Events

I recently started experimenting with a different concept in Flash development, and I want to get some community feedback. As I was starting to define relationships between components in an application I built recently, I realized that part of my architecture was being affected by my use of events. In other words, components seemed to need to be related, which usually meant physically close to each other, in order for it to be convenient for them to be able to listen for events broadcast from each other. I found I needed some common point of contact (a controller) between components that wanted to be aware of other components.

Continue reading…

ColdFusion vs Flash (the conclusion)

I finally finished both the Flash version and the ColdFusion version of the Community Resource Directory, and both are running and in use internally. I learned a lot, especially about Flash MX 2004, and I had a lot of fun building both interfaces.

I thought I would come out of this feeling like one approach was better than the other, however I really don’t have a sense of one being superior in any way. Neither was faster or easier to build (well, maybe the ColdFusion version was a little faster because I had to update my knowledge of Flash and ActionScript, but that was one-time “cost”). And I also don’t feel like either one provides a hugely superior experience over the other. Both clearly have their advantages and disadvantages, which I try to summarize below:

Continue reading…

Network Time and OS X

I’m not sure why it is that computers are so lousy at keeping track of time, but it drives me crazy. Both my alarm clock and my watch synchronize with an atomic clock in Colorado multiple times a day to ensure they are as accurate as possible (to the naked eye, they are exactly accurate), meanwhile the clock on all my computers (including my PDAs) are free wander aimlessly. Well, no more. I discovered the other day that you can configure OS X to synchronize with a network time server by going into System Preferences -> Date & Time -> Network Time, then checking the “Use a network time server” checkbox. Now my computer and my watch are never more than one second apart (for some reason, Apple’s time server is about one second slow), and my PDA gets its time from the computer.

Now I have to find some other excuse for always being late.

Editing External ActionScript Files

I’ve asked about ColdFusion editors before, but now I’m specifically interested in what people are using for ActionScript editing on both Windows and OS X. The built-in editor? Dreamweaver? BBEdit? TextPad? EditPlus? SubEthaEdit? Emacs? What kind of highlighting are you getting, and does anyone have any type of “insight” features working? What do you like about your editor, and what is it lacking? What version of ActionScript are you editing? Don’t hold back!