I wrote this lovely bit of code today whilst confused and frustrated working on a particularly messy command…and its just plain funny.
for(var i:int = 0; i < localSubSwfArray.length; i++){
if( localSubSwfArray[i] is LocalFile){
getDetailsArray.push(LocalFile(localSubSwfArray[i]).uri);
localFileArray.push(localSubSwfArray[i]);
localSubSwfArray.removeItemAt(i);
i--;
}
else panelForTransport.SubSWFs.addItem(localSubSwfArray[i]);
}
I needed to push items into a one array if they were of a particular type, otherwise add them to another array. Thing is I somehow saw it necessary to remove the item from the original array (with no real purpose), which screwed up the positions for the next iteration of the for loop. My fix? Throw a decrement in there to offset it! This actually works despite how unnecessarily confusing it is, it just wasn’t the right solution.
For all you project managers out there, this is a perfect example of why Agile suggest developers never code more than 6 hours a day. Fat chance that any of us will ever see that implemented, but I still like to mention it.
ian News, Projects

Ok, so first off let me say that the iTunes playlist XML structure looks like it was designed by someone who doesn’t even know XML.
Take a look at this entry for a single song:
<dict>
<key>Track ID</key><integer>64</integer>
<key>Name</key><string>Episode 14</string>
<key>Artist</key><string>Gareth Emery</string>
<key>Album</key><string>The Gareth Emery Podcast</string>
<key>Genre</key><string>Podcast</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>64803919</integer>
<key>Total Time</key><integer>2700068</integer>
<key>Year</key><integer>2006</integer>
<key>Date Modified</key><date>2006-09-21T15:14:43Z</date>
<key>Date Added</key><date>2006-09-21T15:14:43Z</date>
<key>Bit Rate</key><integer>192</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>22</integer>
<key>Play Date</key><integer>3264149297</integer>
<key>Play Date UTC</key><date>2007-06-08T16:08:17Z</date>
<key>Release Date</key><date>2006-09-21T11:00:00Z</date>
<key>Sort Album</key><string>Gareth Emery Podcast</string>
<key>Persistent ID</key><string>FE2067001E4F2C00</string>
<key>Track Type</key><string>File</string>
<key>Podcast</key><true/>
<key>Location</key>
<string>The%20Gareth%20Emery%20Podcast/Episode%2014.mp3</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
The way they have this structured makes it impossible to do any E4X based XML processing of the playlist and consequently prevents your from using it in Flex or any other MVC based framework that allows you to easily hook an XML data source into components on the view layer.
So, as if you couldn’t guess, I wrote a class so that you can. You can use it to load in an iTunes XML playlist and turn it into something use-able that adheres to XML best practice where the structure is concerned.
Heres a sample of what it outputs:
<song>
<Track_ID>511</Track_ID>
<Name>Episode 34</Name>
<Artist>Gareth Emery</Artist>
<Album>The Gareth Emery Podcast</Album>
<Genre>Podcast</Genre>
<Kind>MPEG audio file</Kind>
<Size>64804016</Size>
<Total_Time>2700068</Total_Time>
<Year>2007</Year>
<Date_Modified>2007-07-24T16:29:57Z</Date_Modified>
<Date_Added>2007-07-24T16:29:57Z</Date_Added>
<Bit_Rate>192</Bit_Rate>
<Sample_Rate>44100</Sample_Rate>
<Release_Date>2007-07-19T22:00:00Z</Release_Date>
<Sort_Album>Gareth Emery Podcast</Sort_Album>
<Sort_Name>Gareth Emery Podcast - Episode 34</Sort_Name>
<Persistent_ID>DFA5DE7CE96B0316</Persistent_ID>
<Track_Type>File</Track_Type>
<Podcast/>
<Unplayed/>
<Location>The%20Gareth%20Emery%20Podcast/Episode%2034.mp3</Location>
<File_Folder_Count>4</File_Folder_Count>
<Library_Folder_Count>1</Library_Folder_Count>
</song>
Much better, huh? Heres an example of how you can use it in your Flex/AS3.0 project.
var libraryPath:URLRequest = new URLRequest("testlibrary.xml");
iTunesLibrary = new itunesXMLParser();
iTunesLibrary.load(libraryPath);
iTunesLibrary.addEventListener(Event.COMPLETE, loadHandler);
iTunesLibrary.addEventListener(ProgressEvent.PROGRESS, progressHandler);
public function loadHandler(event:Event):void{
trace("Library is done loading, lets do something cool with it");
//trace(iTunesLibrary.playlistXML);
trace("songs: " + iTunesLibrary.playlistXML.song);
var songList:XMLList = iTunesLibrary.playlistXML.song;
//trace(songList);
dg_mx.dataProvider = songList;
}
public function progressHandler(event:ProgressEvent):void{
trace("progressHandler loaded:"
+ event.bytesLoaded + " total: " + event.bytesTotal)</code>
}
Note that it listens on all the same events as the normal XML class. In the loadHandler function above theres an example of how to hook this into a datagrid component in flex.
Thats it. Right now it only grabs songs, I’ll be adding support for multiple playlists later.
Download the class file here
Download the example flex project here
ian AS3.0, Flex, News, Projects

One of things that I’ve always found a bit odd is that you can’t double click on an .flv video file and have it open up in the Flash player like a .swf would. Instead you have to wrap it in a .swf and open that, which is a big hassle. Some FLV compressors like Sorenson Squeeze automatically generate the wrapper .swf for you, but lack playback controls. A better option is to use one of the many FLV players out there. Unfortunately I’ve found that where most them have playback controls they don’t really give any of the juicy information about the video file that us developer types really need to get anything done.
Ideally when I’m working with FLV’s I’d like to be able to see what the position and duration is at all times so that I can easily determine timing for cue points I want to create. I also want to know the display dimensions and the file size, and for all of it I want the option to see the units in a number of different conversions. I also want to be able to drag and drop FLV files so I can very quickly preview them without having to dig 10 directories deep for a folder I already have open.
So, you guessed it, I went ahead and made an AIR application to do just this. Its called FLVinspector. Heres a summary of the features:
- Drag and drop FLV videos onto the application window
- Browse and load FLV videos from the local filesystem
- Reports display size, file size, position and duration
- Change the time and size units settings in the preferences (ms, s, m, B, KB, MB)
Click here to Install FLVinspector 1.0Beta2
*update: currently there is a bug with getting the filesize on FLV’s that have been dragged in. I’ll post an updated version when I get the chance. (FIXED, version is now 1.0Beta2)
ian Air, Flex, Projects
Showcast is a tool for performers to broadcast their shows live over the internet. It makes use of Flash and Flash Media Server. Perhaps the most desireable thing about Showcast is that it is entirely web-based, meaning that anyone with an internet connection and a camera can broadcast with absolutely no setup.
This project is currently under development. Still not certain if this will be open source or not.
ian Projects