Zlib experiments
August 11th, 2006
I’m getting tired, but I have the following for you all, a working sample of this whole compression thing that I’ve become interested in lately. You’ll need Python for this. You should also know how to compile and debug an AS3 class. Save the following code sample as “zlib.py” and put it along with the file you wish to compress somewhere. The file you want to compress should be a text file for this example, although any file will work.
[Python]
#!/usr/bin/env python
import zlib
import os, sys
# Make windows output as binary
if sys.platform == “win32″:
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
if len(sys.argv) < 2:
sys.exit(”No filename given”)
else:
f = open(sys.argv[1], “rb”)
deflate = zlib.compressobj(9)
while 1:
buf = f.read(1024);
if buf:
sys.stdout.write(deflate.compress(buf))
else:
break;
sys.stdout.write(deflate.flush(zlib.Z_FINISH));
[/Python]
Open the directory where you put the files in the command line.
- If you’re using Windows then type “zlib.py filename > compressed.zlib” at the command line. Replace “filename” with the name of the file you want to compress.
- If you’re using Mac OS X (or another Unix OS) first make sure you can execute the file, then type “./zlib.py filename > compressed.zlib” at the command line. Replace “filename” with the name of the file you want to compress.
Save the following Actionscript 3.0 file as “Testify.as” and compile it.
[Actionscript]
package {
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.events.IOErrorEvent;
public class Testify {
static private var url:String = “compressed.zlib”;
private var urlLoader:URLLoader;
public function Testify() {
trace(”Loading “+url);
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE,onComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,onError);
urlLoader.load(new URLRequest(wadUrl));
}
private function onComplete(e:Event):void {
trace(”Loaded”);
var data:ByteArray = urlLoader.data;
urlLoader.data = null;
urlLoader.close();
urlLoader = null;
data.uncompress();
data.position = 0;
trace(data.readUTFBytes(data.bytesAvailable));
}
private function onError(e:Event):void {
trace(”Error”);
}
}
}
[/Actionscript]
Alright, now make sure the “compressed.zlib” is in the same folder as your SWF file, and use either the Flex debugger (flc.exe) or (if you’re using Eclipse) debug the class as an Actionscript project. Your output should be the original file.
ByteArray is the next big thing
August 10th, 2006
Andre Michelle is my personal Flash hero, I find I’m always interested in the things he’s doing. Anyway, his steady obsession with making audio on-the-fly from within Flash has come to fruition and it’s just plain cool. He uses mod files with ByteArray and has managed to hack together a capable audio player. I experimented with mod files but favored midi files instead in a downright weird project I had going a while back. People seem to be slowly realizing how much ByteArray is going to change how people do advanced techniques in Flash.
I’m in the midst of an effort to work out some way to decompress files from within Flash with some help from the people at Flashcoders, although it’s going to be tricky. Basically, you have zip (or gzip) files and Flash, they both use the same compression techniques, but a minor difference makes them completely incompatible normally. But I’ll be damned if that stops me.
This project is DOOMED
August 8th, 2006

This took me about a day. It’s not a pre-rendered image, it’s been grabbed directly from an old-school shareware Doom wad file and imported into Flash.
It’s harder than it looks.
Virtual Music
August 2nd, 2006
I made a poor attempt at a blog on another site a while back, it failed when I lost several drafts in a row to my twitchy browser-closing finger. Plus it was slow as hell. I’m bringing an article over that I always liked about emulated music, which is music taken directly from a video game in its original format. Ironically I rarely listen to video game music, I just like the fact that I can when I feel like it.
This post covers all these formats and more.
- NES
- SNES
- Genesis
- Gameboy
- Gameboy Advance
- Nintendo 64
- Playstation
- Playstation 2
- why Gamecube and Xbox aren’t on this list