Archive

Posts Tagged ‘Coding’

Random Accessing Zip Files with Adobe AIR

September 20th, 2010 16 comments

I’ve recently re-published a new version of hexagonlib, a universal AS3 class library at code.google.com/p/hexagonlib/. Some parts that were originally in the library have been removed, in particular the UI components and the game package. This has been done because I’m working on a game engine (more about that one later) that will probably exclusively include these parts. The hexagonlib is instead targeted at a broader area of development, not just games.

Either way, many classes have been updated and improved (and many still need too *ugh*) and what is particularly worth mentioning are the file IO classes which provide a unified way to work with different file formats. Basically the way how files work in hexagonlib is that you can create file objects of any specific file type (like text, binary, image, XML, etc.), give them a path to a physical file and then add them to a loader (BulkLoader, FileLoader, ZipLoader) which then loads the data of the physical files into the file objects.

While you can use the BulkLoader class to load a collection of arbitrary files in one go with all sorts of comfort (priorities, weighted loading, load retries, multi-connections etc.) the newest addition to the library is the ZipLoader class which can be used in AIR development to access a standard zip file using Random Access. What does that mean? It means that you can create a zip file (a very large one if you want), pack all your resource files that can be loaded by your application and then open it with your app and ‘load’ (= extract) files from it without ever needing to load the whole zip file completely into memory. This makes accessing a large zip file very efficient because only the chunk of the requested, zipped file is loaded.

This is especially interesting for us game developers who desire to use large, nicely packed resource files like they are utilized in a similar fashion in most current day commercial games. For a while I was promoting to add such functionality to AIR over at Adobe Labs but that was before I knew that this can actually be done in AIR since 1.0 thanks to the FileStream class and the position property of it (alas, the property is not available in the URLStream class so random access is not possible on web-based Flash). The ZipLoader uses asynchronous loading to open a zip file as well as ‘loading’ files from it because I don’t like the idea of having the application at the mercy of the file system which would be the case with synchronous access (and which is used in way too many examples on the web).

You can download the hexagonlib distribution over at Google Code, which includes the SWCs and documentation and of course the source code is available for access via SVN. I’m updating the library on a irregular basis. There are already some Wiki pages too with code examples showing how to use the BulkLoader and ZipLoader here but I will hopefully get to write some more in-depth tutorials soon.

hexagonlib at Google Code
File API Wiki
Documentaion

Setting up Eclipse for Flash Developers

April 12th, 2009 35 comments

I’ve been using Eclipse and FDT for several years now to develop Flash (and Flex) applications but I never really managed to set up Eclipse to exactly fit my needs. Either some desired tools were missing or I installed plug-ins that slowed down Eclipse with a truck load of stuff that I never need.

So today I finally figured out how to install the plug-ins that I really need and nothing else (well … almost nothing else). The following guide describes how you can set up your own custom Eclipse tailored for Flash/Flex development which features FDT plus Subclipse, a HTML, CSS, JavaScript and XML Editor and then some. The CSS Editor becomes especially useful for Flex Stylesheets.

Read more…

Categories: Dev Tags: , , , , , , ,

The Confusion about 'this'

December 5th, 2008 23 comments

I often browse through code libraries written by others and can’t deny noticing that so many developers are making exaggerated use of the ‘this’ keyword in their code. Today I came across CASAlib an otherwise very neat and certainly helpful library and after roaming through some of the code base it turns out that in most classes they’ve put ‘this’ in front of every single class property.

It seems that many newcomers to ActionScript still don’t understand the use of ‘this’ and that it’s only really necessary in rare cases, for example if a method parameter has the same name like it’s relative class property or in a few scope-related situations. It’s also good to have ‘this’ at hand if a dynamic property of a class needs to be accessed (this["foo"]) but other than that please do all a favor and throw out those unnecessary ‘this’! Ban it, lock it in your basement and don’t let it out unless there’s really a need for it!

Categories: Dev Tags: , , ,

Understanding Interfaces and Polymorphism

November 18th, 2006 2 comments

I’ve been using Interfaces a couples of time now when needed but I never fully understood those down-sized Class construct wannabes. I knew they are useful when it is required to have an universal type for different objects but I haven’t fully grasped to scope why they are so useful otherwise. Also the fact that they can’t contain properties and only public method declarations confused me.

Read more…

Fixing other people's code

September 22nd, 2006 16 comments

I just had to refuse the second job offer this year where I would have to fix somebody else’s written ActionScript 1 spagetti code! I don’t know what is the reason for agencies trying to give such jobs but it’s save to say that the troubles of digging through the messy and often timeline-spread code is enough to justify an estimate that sounds too high for the client.

The question comes up why they don’t just ask the person who originally wrote the code! That could have many reasons but if a client comes back to me and asks me to fix something in a years old project then I’ll do it for a measly payment simply because I know my source code. It’s a total different thing to fix somebody’s code, especially if it’s pre-AS2.
I always feel uncomfortable rejecting jobs, even such ones so I would be interested how others handle this situation! Do you usually reject such jobs or do you accept them?

Categories: Misc Tags: ,

AS3 Short Variable/Function Names vs Long Ones

August 30th, 2006 8 comments

In ActionScript it was common knowledge that shorter Variable and Function names yielded better performance in situations were it depends but does that still hold true for ActionScript 3.0? I’ve ran a couple of quick tests to find a clear answer about this. I usually tend keep my Variable/Function names to 1-3 characters when performance really mattered but it might actually not be necessary. Consider the following test …

package
{
	import com.hexagonstar.util.debug.Debug;
	import flash.utils.getTimer;
	import flash.display.Sprite;

	public class PerformanceTest extends Sprite
	{
		private var aVeryVeryLongVariableNameaVeryVeryLongVariableName:Number;
		private var num:Number;

		public function PerformanceTest()
		{
			var startTime:Number = getTimer();
			for (var i:int = 0; i < 4000000; i++)
			{
				aVeryVeryLongVariableNameaVeryVeryLongVariableName = (i * Math.random()) * 100;
			}
			var timeTaken:String = getTimer() - startTime + " ms";
			Debug.trace("timeTaken (long): " + timeTaken);
		}
	}
}

I've ran this code ten times with the 50 characters long variable name and then ten times with a 3 characters long one, both in their own SWF's. The results ranged from 757ms to 820ms, more or less the same on both sides. The sum of the long variable version was 7924ms and the one of the three characters long one was 7903ms, not much of a difference.

The next test was similar but this time with a 50 characters long Method name and the other again with a 3 characters long one, the Methods returned a random Number for 4000000 times during this test. The results looked similar but the total sum of each test gave a 12044ms for the long name test and 15570ms for the short named one. A noticable difference of over 3 seconds. This might have been coincidence but I've ran the tests a couple more times and it turned out every time that the result were very close together. This is quite interesting because I was safely believing that short names would still have an advantage. It might be time to rethink this.

More Coding Fonts

July 21st, 2006 3 comments

Found these today on my daily dose of Stumble Upon random links … Proggy Programming Fonts! Still coding with Courier? Maybe it’s time for a change?!

Categories: Misc Tags: , ,

The anachronism of Assembler coding

August 22nd, 2003 No comments

I’ve been selling and buying antique computer stuff on Ebay and also managed to get an old Commodore C64G! The G model was the one with the brown bread bin case and brighter keyboard which was introduced later after the C64C model actually got sold.

This brought up some moods of nostalgia remembering the ‘good old’ days of computing and playing 8bit games. I even found some old 5 1/4″ floppy disks with old tools and games and tried to code some assembler which is even fun in a special way compared to the today’s luxury of coding applications.

There’s also now – as you might already have found – a new category named downloads in which I will put various stuff to leech down from time to time.

Besides there are still some draft entries on hold and unfinished yet on the authoring side. I’m going to finish them when I think it’s time!

Categories: Dataleak, Misc Tags: , ,