Friday, August 08, 2008

Today, I will be the first in the world to propose a new programming language called Obscene. You got it, it's a programming language that use obscenity and sensual words. Enough of the academic bullshit, I think programming should be a stimulating process and reading code should be a trip to the Vegas strip joint. Good code makes you want to come, bad code makes you want to puke.

With this new language, no longer will the compiler scream at you for typing pubic instead for public, and fuction instead of function. Interfaces will be prefixed with I as usual, but takes on a whole new entire meaning. IPhone...IWatch...ITouch, oh yes, IlikeIt.

Wednesday, August 06, 2008

Freaking error: "Workspace in use or cannot be created, choose a different one"

A few times in the past few weeks when I restarted Flex Builder, I would get this error: "Workspace in use or cannot be created, choose a different one". Nothing online says much about it. Just today I found the solution to this. Basically if the java VM is still running (which is probably locking up the folder), you would get that message. Simply kill the process javaw.exe, you are good to go.

Wednesday, July 23, 2008

Whatever frame rate you set to your Flash project to, always test it under a low frame rate setting (such as 10fps) to make sure everything still works solidly, and this will allow you to see how your app behaves on low end machines.

Saturday, July 19, 2008

Debugging Tip #2

Another snippet that is useful for debugging is the flash.system.System.totalMemory.

trace(Number(System.totalMemory / (1 << 10));

This will display the total memory in KB.

To display it in MB,

trace(Number(System.totalMemory / (1 << 20)).toFixed(2));

Debugging Tip

At times you might find yourself wanting to know if your swf is running in a debug version of Flash and behave accordingly. You can do this by making use of the fact that Error class's getStackTrace() returns null when running in non-debug version of Flash player.

function isDebugPlayer( ) : Boolean
{
return Boolean(new Error().getStackTrace());
}

Actionscript 3's Array and String are now more improved and has a lot of methods found only in the popular scripting languages such as Perl, Python, etc.

If you are not aware of these changes, you should hop over to
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html
right away.

New array methods you will find useful:

indexOf, lastIndexOf
every, some
filter - filter out the items that pass your test into a new array
forEach - transform all array items in one fell swoop in place
map - similar to forEach, but returns the new transformed items in new array


Some of the new useful string methods:
search
match
replace - no more custom solution!

Tuesday, July 15, 2008

Colin Moock had a blog post today on the things you need to do to totally unload a swf from your code, I am attaching them here for convenience:
--- snip ---
  • Tell any loaded .swf child assets to disable themselves.
  • Stop any sounds from playing.
  • Stop the main timeline, if it is currently playing.
  • Stop any movie clips that are currently playing.
  • Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, NetConnections, and NetStream.
  • Release all references to cameras and microphones.
  • Unregister all event listeners in the .swf (particularly Event.ENTER_FRAME, and mouse and keyboard listeners)
  • Stop any currently running intervals (via clearInterval()).
  • Stop any Timer objects (via the Timer class’s instance method stop()).
-- snip --

More info can be found at http://www.moock.org/blog/archives/000279.html

One thing to take away from this is that when you are working out your code architecture, you can try to obtain a lot of the resources above through a single point of access. While this will inherently increase the coupling of your code to that one component, it does have the benefit of allowing you to easily manage all your resources in one place and do all the cleanup work in one place. Something to think about.

Monday, July 14, 2008

Actionscript 3 Class Destructor (in my dream)

I wish Actionscript 4.0 will come with a destructor. It's so useful to not only know when your object is born, but when it's about to die as well. Even though AVM implements garbage collection scheme, there is still no reason why we can't have a destructor. The moment an object becomes a candidate for garbage collection, its destructor can be called and us the users can do whatever we want (such as doing cleanup work, tracking for memory leaks, prepare an epitaph for the object (jk), ...)

Sunday, July 13, 2008

Loader and URLLoader

If you are just starting out coding in Actionscript 3, at times you might find yourself asking: What is the difference between Loader and URLLoader? Well, before you get asked by someone to RTFM, just remember that Loader inherits from DisplayObjectContainer, so anything that you might use for display purposes (such as swf, jpg, png etc.) you will load it via Loader. URLLoader, on the other hand, inherits from EventDispatcher, so anything that you use as data (such as xml, text file, etc.) you will load it via URLLoader.

Using namespace for your Flex library swc

I downloaded degrafa today, and built the swc from source. I wanted to use the library like so in my MXML file:

First time when I built it, I got an error trying it the above way.
Read up on the doc, and this time I included the Namespace URL and Manifest file path in Project Properties->Flex Library Compiler.
Tried it again and still no go, got some dumb "Could not resolve x to component implementation" error.
Read up the doc one more time on the compiler option one more time, this time I included another parameter -include-namespaces and rebuilt the project, and it worked.