How to fix Flash Builder broken workspace.

From time to time I get weird Flash Builder/OS X crashes which lead to Flash Builder (Eclipse) freeze or hang up during startup. You think you have to recreate your workspace every time after a crash, but no, if that happens there’s a solution.

So, if Flash Builder freezes trying to load your workspace what you need to do to fix it is to navigate to .metadata/.plugins/org.eclipse.core.resources and delete the file named .snap. That’s it. No more rearranging views and reimporting projects!

More on faster MD5

All of you who liked the first version of famous algorithms on steroids library from blooddy will be pleased by the new release. This time it’s even faster and more stable. The author got rid of some bugs too (like this one).

Also at last he hosts the file himself so I finally can cut my traffic bills by half.

Where’s my byte, dude??!

While working on his famous library blooddy stuck upon what appeared to be a flash bug. Sometimes an empty ByteArray is not THAT empty at all.

Basically if you write something to it first you can get non-zero bytes in your new ByteArray other than you just wrote yourself.

bytes.writeUnsignedInt( 10 );
 bytes.length = LENGTH;

But if you set the length first everything runs smoothly. Be careful!

Tired of people using stage in constructor?

Recently someone in ruFlash user group asked if it’s possible to get rid of errors when loading a SWF which thinks it is the only SWF in the world and there totally must be stage available in its constructor. As you already understood such SWFs fail with Null Access errors.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

This task looks like a great exercise for my epic Scala skills I got trying to understand famous Joa‘s code.

Thanks to apparat and Scala I managed to code a small app which rewrites SWF files and moves all constructor code to a private method which is later subscribed to ADDED_TO_STAGE event.

usage: java -jar initInjector.jar [-c] <from.swf> [to.swf]“)
-c — check for references to stage in constructor
If [to.swf] is not specified resulting SWF is saved to <from.swf>

The 0.1 version fails to move exceptions though. Trying to grasp that bytecode exceptions magic atm.

Here’s the application: initInjector.zip

100x times faster MD5 and more

Update: Get more recent version of the library here.

Update: I updated the zip with LGPL MIT license file. The original author basically says “use wherever you want” which looks like mostly LGPL MIT, right? Yes, haXe was used to create the SWC but I don’t know if we can get the source or not. Anyway I hope you understand from the code below how to use the library.

My dear friend BlooDHounD has recently released an SWC with highly optimized MD5, Base64, CRC32, JPEG, PNG algorithms. Compared to as3corelib we get the following results:

by.blooddy.crypto.MD5.hashBytes: 40
com.adobe.crypto.MD5.hashBytes: 4483

by.blooddy.crypto.Base64.encode: 115
mx.utils.Base64Encoder: 1635

by.blooddy.crypto.Base64.decode: 141
mx.utils.Base64Decoder: 2762

by.blooddy.crypto.image.JPEGEncoder.encode: 447
com.adobe.images.JPGEncoder: 3496

by.blooddy.crypto.image.PNG24Encoder.encode: 538
com.adobe.images.PNGEncoder.encode: 1423

Here’s the benchmark source:

package {

	import by.blooddy.crypto.Base64;
	import by.blooddy.crypto.MD5;
	import by.blooddy.crypto.image.JPEGEncoder;
	import by.blooddy.crypto.image.PNG24Encoder;

	import com.adobe.crypto.MD5;
	import com.adobe.images.JPGEncoder;
	import com.adobe.images.PNGEncoder;

	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.utils.ByteArray;
	import flash.utils.getTimer;

	import mx.utils.Base64Decoder;
	import mx.utils.Base64Encoder;

	[SWF( scriptTimeLimit=&amp;quot;255&amp;quot; )]
	public class test extends Sprite {

		/**
		 * Constructor
		 */
		public function test() {
			super();

			var text:String = '';
			var t:Number;

			// BitmapData for tests
			var bmp:BitmapData = new BitmapData( 1024, 1024, true, 0xFFFF0000 );
			bmp.noise( int( Math.random() * int.MAX_VALUE ), 0, 0xFF, 7, false ); // генерируем шум

			// ByteArray for tests
			var bytes:ByteArray = bmp.getPixels( bmp.rect );

			// MD5 test
			t = getTimer();
			by.blooddy.crypto.MD5.hashBytes( bytes );
			text += '\nby.blooddy.crypto.MD5.hashBytes: ' + ( getTimer() - t ); // 40

			t = getTimer();
			com.adobe.crypto.MD5.hashBytes( bytes );
			text += '\ncom.adobe.crypto.MD5.hashBytes: ' + ( getTimer() - t ); // 4483

			// Base64 encode test
			t = getTimer();
			var s1:String = by.blooddy.crypto.Base64.encode( bytes, true );
			text += '\nby.blooddy.crypto.Base64.encode: ' + ( getTimer() - t ); // 115

			t = getTimer();
			var e:Base64Encoder = new Base64Encoder();
			e.encodeBytes( bytes );
			var s2:String = e.flush();
			text += '\nmx.utils.Base64Encoder: ' + ( getTimer() - t ); // 1635

			// Base64 decode test
			t = getTimer();
			by.blooddy.crypto.Base64.decode( s1 );
			text += '\nby.blooddy.crypto.Base64.decode: ' + ( getTimer() - t ); // 141

			t = getTimer();
			var d:Base64Decoder = new Base64Decoder();
			d.decode( s2 );
			d.flush();
			text += '\nmx.utils.Base64Decoder: ' + ( getTimer() - t ); // 2762

			// JPEG test
			t = getTimer();
			by.blooddy.crypto.image.JPEGEncoder.encode( bmp, 60 );
			text += '\nby.blooddy.crypto.image.JPEGEncoder.encode: ' + ( getTimer() - t ); // 447

			t = getTimer();
			( new com.adobe.images.JPGEncoder( 60 ) ).encode( bmp );
			text += '\ncom.adobe.images.JPGEncoder: ' + ( getTimer() - t ); // 3496

			// PNG test
			t = getTimer();
			by.blooddy.crypto.image.PNG24Encoder.encode( bmp );
			text += '\nby.blooddy.crypto.image.PNG24Encoder.encode: ' + ( getTimer() - t ); // 538

			t = getTimer();
			com.adobe.images.PNGEncoder.encode( bmp );
			text += '\ncom.adobe.images.PNGEncoder.encode: ' + ( getTimer() - t ); // 1423

			var tf:TextField = new TextField();
			tf.autoSize = 'left';
			tf.text = text;
			super.addChild( tf );

		}

	}

}

I know that he is too shy to tell you guys about his results (8
But they are definitely worth sharing.

You can download the SWC here (look up at the update section).

AVM2Overview lies

It says:

One of the entries in the ABC file is an array of script_info entries (see the next chapter). Each of these entries contains a reference to an initialization method for the script and a set of traits to be defined in the script’s environment. The last entry in that array is the entry point for the ABC file; that is, the last entry’s initialization method contains the first bytecode that’s run when the ABC file is executed.

That’s apparently is not true. I keep getting different classes in the last entry except the main document class which I need. Thanks to @joa for pointing me to SymbolClass tag which contains an array to map Classes to Library Symbols in SWF files. And the very first class there seems to be the Document class I need.

The world desperately needs flash

Just read an article about Smokescreen, which “It runs entirely in the browser, reads in SWF binaries, unzips them (in native JS), extracts images and embedded audio and turns them in to base64 encoded data:uris, then stitches the vector graphics back together as animated SVG.” for iPhone/iPad.

Wonder what people can do just to see flash in iPad.

This thingie can only render flash banners. And we all know that banners is the most important and advanced thing of all flash stuff.

Protecting flash games

Last Thursday I spoke at FlashGamm 2010 Moscow about how to protect your game from hackers. Though, slides alone can’t substitute my long monologue, I uploaded the presentation (in Russian and English) here. I hope it will be useful for you guys.

The hardest tetris ever

True story.

Flash on Microsoft’s site

Well, the site for Russian launch of Visual Studio 2010 is a piece of crap. A piece of silverlight crap. Just check the sources. IT IS AN ABOMINATION!!!

What’s more, the actual game is not in Silverlight, it is in Flash. And it fails with errors on some timer event which don’t go away.

Microsoft “can” make Flash. OLOLOLOLOLOL!!!!

ms-lol