Archive

Archive for the ‘Actionscript’ Category

mDNS daap announce AIR 2.0

June 30th, 2010

This morning I woke up with the need to try something new.
Never had the time to play with the new AIR 2.0 features or most of the new FP 10.1 features.
So I had to create something that is useful (for me at least) and uses some (in this case just one :P ) new feature of AIR 2.0.
This nice new class is called DatagramSocket. With this class you can send UDP packages... wait... UDP :D
Read more...

Bernard AIR, Actionscript, Source

Using ByteArrays in Actionscript and Alchemy

March 31st, 2009

A few days ago I got the question how I did the transfer of data between Actionscript and C (Alchemy).
There are a few ways to push ByteArrays back and forth, I will give some examples of the methods I used.
Read more...

Bernard Actionscript, Alchemy, Source

MP3 encoder in Flash with Alchemy

March 24th, 2009

A week ago I started playing with Adobe Alchemy. First just a few return values or simple calculations.
After a few days of playing and testing I thought it would be nice to have a MP3 Encoder in flash.
With the new Sound.extract method in Actionscript you can get raw data like a "WAV" but there is no easy way to compress this data.

I started searching for C code which implements a MP3 Encoder and found the 8Hz MP3 implementation.
I could have used LAME, but hey.. have you looked at the file count!
The 8Hz implementation uses about 10 files, so it's readable. It's not the best encoder, but good enough to test the possibilities.

I was very surprised that the 8Hz code would compile with llvm-gcc (Alchemy)! That is a good starting point, now I only have to rewrite some code to get input from and output to Actionscript.

The original source used fopen to read and write files. This isn't possible with Alchemy so I replaced fopen with funopen and gave a pointer to Actionscript bytearrays.

The next problem I encountered was the execution timeout in Flash. When encoding large WAV files (more then 30 seconds of sound on my MacBook Pro) the flashplayer will trigger an error about exceeding the maximum execution time. I tried to alter it with the compiler option "-default-script-limits" but no luck (maybe it has something to do with Alchemy).
But it forced me to take a deeper look in the encoding source. I've rewritten the layer3.c file to process a few frames and then give feedback to Actionscript. This way no timeout occurs.

I'm still working on speed optimization, because encoding is slow at the moment.
I will keep you updated!

Here is the first version:

Bernard Actionscript, Alchemy, Flash

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]);
		audioData.writeBytes(aframe.frameData);
		currentSamples = (currentAudioFrame+1) * (576*2);
		currentAudioFrame++;
	}
 
	var samples:int = currentSamples - startSamples;
	var seek:int = startSamples ? needSamples - startSamples : 0;
 
	var af:AudioFrame = mp3.audioFrames[i] as AudioFrame;
	_swfBytes.writeShort(createHeader(SWFTags.SOUNDSTREAMBLOCK,63));
	_swfBytes.writeInt(audioData.length+4);
	_swfBytes.writeShort(samples);
	_swfBytes.writeShort(seek);
	_swfBytes.writeBytes(audioData);
	_swfBytes.writeShort(createHeader(SWFTags.PLACE_OBJECT2,3)); //Place frame data
	_swfBytes.writeByte(1);
	_swfBytes.writeShort(1); //depth
	_swfBytes.writeShort(createHeader(SWFTags.SHOWFRAME,0));
 
	i++;
}

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

http://www.airdoc.be

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