Archive for February, 2009

MP3 to SWF converter in Actionscript 3

February 13th, 2009

A while ago I was playing with SWF generation within Flash itself.
I read the Adobe SWF specs and now I'm able to generate SWF's from FLV's and MP3's or both.

A simple Flash 10 example, haven't tested all possible MP3 rates so if someone encounters a bug, please let me know.
(Just found out that some MP3's with embedded art-work won't work... added to my TODO's).

Code snippet which writes the MP3 data to a SWF bytearray:

while(mp3.audioFrames.length > currentAudioFrame)
	var needSamples:int = 0.001 * ((1000/(__frameRate))*i) * audioRate;
	var startSamples:int = currentSamples;
	var audioData:ByteArray = new ByteArray();
	while(mp3.audioFrames.length > currentAudioFrame && currentSamples< needSamples)
		var aframe:AudioFrame = AudioFrame(mp3.audioFrames[currentAudioFrame]);
		currentSamples = (currentAudioFrame+1) * (576*2);
	var samples:int = currentSamples - startSamples;
	var seek:int = startSamples ? needSamples - startSamples : 0;
	var af:AudioFrame = mp3.audioFrames[i] as AudioFrame;
	_swfBytes.writeShort(createHeader(SWFTags.PLACE_OBJECT2,3)); //Place frame data
	_swfBytes.writeShort(1); //depth

This way I write all SWF headers the correct way and not like most other code out there which uses a precompiled SWF and replace the sound object.

Bernard Actionscript, Flash

Doc? Air Local LiveDocs

February 12th, 2009

Doc? is an Air application that allows you to view your documentation outside of your IDE.
It supports Flash CS3 documentation, Flash CS4, Flex and ASDoc.

Searching can be done by keyword or by regular expression!
Doc? provides two plugins, one for Flash and one for Eclipse (Flex, FDT etc..). These plugins send the selected text to Doc? and Doc? will search it's database for matching items.

I love it :D

Screenshot with the PV3D ASdocs imported:

Papervion API in Doc?

Papervion API in Doc?

Bernard Actionscript, Flash, Flex

Replace HTML encoded characters with their original ones

February 12th, 2009

Just a simple regular expression to replace all HTML encoded characters with their original ones.

var testString:String = "This is a test with a &#8211; character and a &#8217;";
testString = testString.replace(/&#([0-9]+);/g, replaceCharacters);
private function replaceCharacters(...args):String
	return String.fromCharCode(parseInt(args[1]));

Bernard Actionscript

Blog online..

February 12th, 2009

I thought it was about time to get my own blog online.
Now just thinking... what should I blog about..

Bernard Uncategorized