cinqetdemi.Config: a plist config file reader for Flash

Posted on Tuesday 16 May 2006

Feeling limited with FlashVars, and frustrated with custom xml formats that don't retain type information, I followed former colleague Will Prater's advice and implement a plist loader and partser for Flash.

plist is an xml dialect by Apple specifically suited for configuration files which retain type information. Your plist file should contain a top-level node, and can contain , <integer>, <real>, <date>, <array>, <dict>, and <key> nodes. Here is a typical plist file:


<plist version="0.9">
        <dict>
            <key>christmasEve1999</key>
            <date>946080000000</date>
            <key>whiteAsSnow</key>
            <integer>0xffffff</integer>
            <key>aDeliciousNumber</key>
            <real>3.141509</real>
            <key>pythonIngredients</key>
            <array>
                <string>Spam</string>
                <string>Eggs</string>
            </array>
            <key>flashPeople</key>
            <dict>
               <key>flashguru</key>
               <string>Guy Watson</string>
               <key>jesterXl</key>
               <string>Jesse Warden</string>
               <key>mesh</key>
               <string>Mike Chambers</string>
            </dict>
        </dict>
</plist>
 

Admitedly, the format is a bit verbose, but it serves its purpose. The parser will transform this into:


{christmasEve1999:new Date(946080000000),
 whiteAsSnow:0xffffff,
 aDeliciousNumber:3.141509
 pythonIngredients:['Spam', 'Eggs'],
 flashPeople:
  {flashguru:"Guy Watson",
   jesterXl:"Jesse Warden",
   mesh:"Mike Chambers"}
}
 

Usage:


import cinqetdemi.Config;
import mx.utils.Delegate;

var config:Config = Config.getInstance();
config.addEventListener('load', Delegate.create(this, onConfigLoad));
config.addEventListener('error', Delegate.create(this, onConfigError));
config.loadConfig();

function onConfigLoad()
{
    trace(config);
    trace(Config.getConfig()); //A shortcut with static access
}

function onConfigError()
{
    trace('Gosh darn it!');
}
 

By default, the config file will be loaded from config.xml in the same directory as the swf. You may also specify the file name using the .fileName property before calling loadConfig().

The loading will time out after 7 seconds and dispatch an error event

License: BSD

Download it here (v1.0)


WordPress database error: [Can't open file: 'wp_comments.MYD'. (errno: 145)]
SELECT * FROM wp_comments WHERE comment_post_ID = '196' AND comment_approved = '1' ORDER BY comment_date

No comments have been added to this post yet.

Leave a comment




Your e-mail address is never displayed. If you run into issues with SpamKarma blocking you, email me at $patrick->5etdemi(com)


RSS feed for comments on this post | TrackBack URI