[AS3] StateView

StateView by thienhaflash (thienhaflash@gmail.com)
Updated			: 26.Feb.2012
Callbacks 		: -
Features 		: 
	Automatically get the children of a container use as states
	Support optional custom transitions when changing states
	Support optional callbacks on each child to be called when transition start / end
		(onStartIn, onStartOut, onEndIn, onEndOut)
	Automatically disable interaction and block state changes while doing transition
	Fully trace for invalid operations for easy tracking down
	No dependencies (don't even need a tween engine)

Continue reading

Flash xfl format – A dirty secret

One of the new exciting features of Flash CS5 is the arrival of the new source file format : XFL – which is a non-compress, text(xml)/raw assets-based version of the fla format. What is this good for ? Version control to be the first ! As symbols are now xml files, once we making changes we can always tracking down by doing a diff comparison to find out what all the changes are. Secondly, all assets are now exposed and artist can change it any time to make an update.

The disappointed thing is it’s not just working that way. The more i used new XFL format, the more I got angry about how useless it is.
Continue reading

[haxe] HDictionary

When trying to implement a new event system that support custom parameters in Haxe, I come across the need of AS3 Dictionary. After doing a quick search I found that there are no Haxe equivalent (yes, there is TypedDictionary but it’s only available if you are targeting Flash). To me, there is no point to write in Haxe if we can only target one platform, so I bring it up to create a HDictionary that works similar to AS3 Dictionary in pure Haxe hopefully this will be helpful to someone out there.

The basic idea is simple, as we do not has any kind of object signature (a unique string equivalent, usually its memory address) to use as the key, we need to store both key and value and then make a loop through all the items, doing comparison until we come across the correct one. You might think that this will cause much overhead (searching a lot) but remember that whatever type of script we used, this overhead can not be avoided.
Continue reading

[AS3] Input

In the efforts to unify the AS3 libraries i realized that writting too many files (each file is specific for one functionality) though very clear and easy, maintainable is a big issue. I usually need to bring the whole library, which caused conflicts to another project when there might be other versions of utils classes (btw, i used to put package’s function for each utility) happen to be there. This caused too much headaches as the old ones will might not work the way we expected with the new ones, overwrite is not an option, especially when the classes was patched for bugs in different projects. Of course, life should be easier if you track down everything you modified to a class got used in the real project or got simple unit test for each file, but still, the portability is not that great.

One class for one thing should be the way to go, though it’s heavier in term of code base, the maintainable process should be easy enough, just move it somewhere, rename the package once if needed. No missing or conflicted dependencies to worry about …

One cool thing in this version is that you don’t need to cancel out theme configuration : if a state used bold = true, we don’t need to cancel out for other state, aka, doesn’t need to put bold=false for each other states. Another one is that we can do input configuration from timeline.
Continue reading

Batch publish .fla files

JSFL is the way to automate tasks in Flash CS IDE, you can write extensions to do the repeating works like export fonts, open files, create symbols, read graphics datas, build multiple .fla files … The one thing i got astonished about is that there are no built-in way (no jsfl api) to know if there are errors during compilation of an .fla file. Hit ctrl+enter, you see that even if there are errors in code, the Flash IDE still trying to launch the .swf file. Hit build from an .flp project, the compiling process won’t stop when errors occurs for files, it just clear the log everytime a new file need to build, so we end up with a bunch of errors in files which we never where they are to apply the fixes.

I don’t know how hard it is for the Flash CS team to add an api allowing us to catch and stop when there are errors building .fla file, but this surely make enough troublesome for me : Once there are errors, i need to wait for the batch building complete then compile one by one manually… so finally decision, there must be a way to do it in jsfl.
Continue reading

MultiKey Dictionary

While developing some kind of event monitoring Manager class i come across a problem of too many Object used : Each IEventDispatcher source can dispatch multiple eventNames, each eventName can have several function attached to it. The popular approach is using nested Dictionary/Object as the main data structure :

_sourceDict : Dictionary; /* map IEventDispatchers to _eventObjects */
_eventObject : Object; /* map eventName to _handlerDict */
_handlerDict : Dictionary; /* map handler to its params */

For faster check and overwrite the existed _handler for a specific source and eventName we need to use a Dictionary for _handlerDict instead of an Array, and by the way, add support for user parameters.

This data structure of course will still work without any problem even though the code looks busy by nested properties access. We might also got slow down by looping through those nested structure. Let’s have a look through another implementation where we save multiple values as the key instead of only one.
Continue reading

Indexed Linked List

Indexed Linked List is an improved version of Single Linked List that enable random access (can only found on Array) and fast item splicing (can only found on Linked List). We can use it for prioritized queues where items often got inserted / removed at arbitrary positions. Some popular applications are loading queue manager (sort by priority), delayed tween list (sort by delay), or custom Event Dispatcher (addListeners with priority).


We have a single linked list (to cut memory cost 30% compared to double linked list), every item has a {.next} pointer point to the next item in the list. Every item has a {.priority} property to be used as mandatory sort term, a {.time} stamp for secondary sort term, this way, every item is unique and can be compared to each other without equality worries.

Besides the normal linked list implementation we have another Array {_grid} to keep track of pivots items at some rough space {_gridSize}, that means for every roughly {_gridSize} items in the list we save an item into the {_grid}. This kind of indexing will enable binary search for position of any item in the list which means fast random access to items (fixed (and small) time to reach any item in the list). Of course, this won’t beat Array’s random access, but it’s fast enough for practical use ! Continue reading


One of the most common data structure in Flash is Array, which provides a fast way to construct a list of data items with compact memory cost. This data structure is working fine and rather fast, except for some operations, for example, insert / remove items randomly (splice) or pushing things to the beginning of the Arrays (unshift). Because of the compact memory implementation, all the existed items after the insert position will need to be migrated. With o(n) complexity, operated time goes up linearly with the number of items. And it’s just the same for Vector, although Vector is way faster than Array as there are no dense checking and converting between Dense Array & Hash Table (there are more reasons ? ). In short : Array is slowing down by items migration

A rather popular solution is using Linked List – either double or single. Linked list has ability to add and remove items very fast at an arbitrary position as no item is being migrated. Double linked list cost more memory (~ 1.5x ) and a bit slower than single Linked List (which, consume 2x more memory than Array) but it allows traversing in both direction. For some operations, the doubles run faster (~ 2x faster) than single ones. But as we won’t have random access to items by numeric indexes like Arrays, it’s really slow if we need to skip forward / backward to get to some random position. In short : Linked List is slowed down by skipping to specific position  Continue reading

A better AS3 Singleton implementation

As a developer we usually need to create libraries to reuse in various projects, most of them are of the manager style : one class (or instance) to handle all in coming tasks from various places, popular examples are : Tween engines, Loading services, 3D libraries, Sound processing library … The simplest implementation is the static-class-methods way.


Let’s have a look through a simple library class :

package {
	public class MyUtility {
		public static function methodA(): void {
			//do A things here
		public static function methodB(): void {
			//do B things here

And its simple usage syntax

MyUtility.methodA();//call method A
MyUtility.methodB();//call method B

Continue reading


After using Gaia for a long time with numerous websites built, i can tell you that completely like it as the workflow is simplified so much, i really love the scaffolding, assets managements, contextMenu, event hijacking, routing, assetPath, tracking, binding expression, the complete integration of SWFAddress, SEO … everything ! But that’s not to say there are no more room to get improved. Let’s dig in for more details !

    Continue reading