28 March 2010

as3signals: new approach for AS3 Events

There are times you may find that the built-in events of AS3 are limited and even troublesome. Here are some circumstances that EventDispatchers turn against developers:
  1. Objects MUST extend EventDispatcher in order to be able to dispatch events. Implementing IEventDispatcher alone is impossible because the event target is read-only and you cannot change it from outside of EventDispatcher.
  2. It’s difficult to manage events. There’s no way you can remove all event handlers attached to an event dispatcher at once. So in some cases, you don’t remove them properly and they start causing bugs. (BTW, using weak references is not reliable and not recommended.)
  3. You cannot pass extra data to you listener unless you extends a new Event object
  4. You cannot set up your interface in a way that it can enforce implementing classes to dispatch the required events.
  5. On performance perspective, creating objects is one of the most evil things. That’s why any advanced programmers must know and practically use objects pool. However, we are still wasting a lot of resources creating event objects, especially repetitive events like mouse move or enter frame.
  6. Read here for more critiques on AS3 events
So in order to address those issues, Robert Penner has adopted an alternative to AS3 events namely as3signals. (Follow the link for more info and get the library)

21 March 2010

AS3 Type Conversion & Common Mistakes

In this article, I’ll discuss some common mistakes that AS3 developers (including myself) often make when working with (implicit) type conversion.

1. Check whether a dynamic property is set

Dynamic properties can be added to dynamic object at run-time. Consequently, there’s often a need to test whether they are set before using them.

Here’s how some developers do it:

  1. var initObj: Object = {embed: true, color: 0xFF0000, text: "Hello" };
  2. /* ... */ 
  3. if (initObj.embed) { /*apply embed*/ }
  4. if (initObj.color) { /*apply this color*/ }
  5. if (initObj.text) { /*apply this text*/ }

The first test with Boolean is ok. But be careful when the input for color is black (0x000000) or the text is empty (“”). In that case, zeros and empty strings casted to Boolean equal false, and definitely the code will run incorrectly.

So, the best practice to check whether a dynamic property is set is to do as following:

  1. if (initObj.embed != undefined)
  2. if (initObj.color != undefined)
  3. if (initObj.text != undefined)

12 March 2010

Case Study Isometric Multi-player Virtual World

mattel

This is my team’s case study to demonstrate our capability to build a MMORPG (Massively Multiplayer Online Role Playing Game). The site features 2.5D isometric scene and realtime multiplayer virtual world utilizing SmartFox server.

My role: key researcher, team leader

Tech notes:

  • Flash Player 9 / Actionscript 3
  • AS3IsoLib Isometric engine
  • Red5 server (in first phase)
  • SmartFox multiplayer server (Java backend)

Project ASB Minisites

ASB Horsemen Minisite

This is an all-flash minisite for a key flying performer team from Air Show Buzz community. This site is to deliver videos, photos and other information related to the team in a centralized and convenient way. The site features PureMVC framework in the front-end flash site and PHP as backend services. The site was designed in a way that new contents and panels can be added/removed dynamically, and theme color can be changed via XML-based site config. (In fact, with the same swfs, it has been cloned into a few other minisites.)

My role: Technical leader

Tech notes:

  • Flash 9 / Actionscript 3
  • PureMVC framework
  • Flash CS3 & Flex SDK workflow
  • Clearspring sharing service
  • Google Map API for Flash

image2 image7

Project Smile Shutter

Smile Shutter 

This is a another key campaign site (2009) for Sony Ericsson to show off their latest mobile phones with smile capture technology (C510, C903). Apart from Flex and Cairngorm framework, this site features SOAP service communication and complicated back office management to handle a big photo gallery and users database. The site is also localized into over 30 languages.

My role: Flex technical leader; Flex developer

Tech notes:

  • Flex 3 / Actionscript 3
  • Cairngorm MVC micro-architecture framework
  • Loaded CSS (dynamic font & styles)
  • Custom effects
  • XML-based localization
  • SOAP services
  • Large scale photo gallery (.NET backend)

Smile Shutter Home Page Smile Shutter Gallery

07 March 2010

Ubuntu for Flash Developers

I love Linux and free (but cool) softwares. But running Linux as a pure environment for Flash development seem to be a mission impossible (at least to the time of this post). Although I have discovered many good alternative programs, the most needed Flash authoring tool – Flash CS4 is not available in Linux. And that prevents me from moving 100% from Windows to Ubuntu.

Here are the list of application choices in Ubuntu which comes from my own experiences that I think necessary for any Flash developers to work comfortably in Linux world:

No

Tool

Windows application

Linux alternative

Note on Linux alternatives

01 Flash IDE or Fla authoring tool Adobe Flash CS4 N/A make do with Virtual Box + WinXP + Flash CS4 (cost a lot of RAM)
02 ActionScript editor FlashDevelop (free and cool)

Eclipse + FDT plugin or Flex Builder 3 alpha

FDT Basic is free but lacks refactoring and debug tool (however it is comparable with current FD version)
03 Flex & MXML tool Flex/Flash Builder Eclipse + FDT plugin or Flex Builder 3 alpha Currently, there is no tool comparable with Flash Builder in MXML design.
Flex Builder in Linux doesn’t have MXML design either.
04 Flash trace & debugging Debugger in Flex Builder and Flash tracer in Firefox. Flash tracer in FF and MAYBE debugger of FDT I haven’t tried debugging with FDT.
05 Browsers and web debugging tools Firefox + Firebug
OR IE + Fiddler
Firefox + Firebug It is as ‘comfy’ and easy as in Wins
07 Personal web host for testing IIS or Apache Apache  
  Other professional tools  
08 VPN Client Cisco  Systems VPN Client Built-in Network Manager + VPNC package Very convenient VPN solution
09 Chat / IM Yahoo, MSN Pidgin

Pidgin manages both of my Yahoo & MSN accounts.
There are, in fact, some limitations compared with the original applications.

10 Voice conference Skype Skype for Linux Not fully functional like Windows’ counterpart but it’s still the best voice chat application
11 FTP client Filezilla FileZilla  
12 SVN client TortoiseSVN RabbitVCS + RapidSVN Inspired by TortoiseSVN, RabbitVCS is an integrated client working as shell commands in Ubuntu’s default file manger – Nautilus. By the time of this post, there’s still an issue with authentication so I need rapidSVN for first checkout.
13 Screen capture Fastone Capture (free version) Shutter Shutter comes with a handy drawing tool for taking notes and marking. BTW, the Ubuntu default tool “Take Screenshot” really sucks.
14 Remote desktop viewer Remote Desktop Connection OR VNC viewer Terminal Server Client OR Remote Desktop Viewer Terminal Server Client is totally comparable with Windows’ RDC
15 Office suite Open Office or MS Office Open Office  
16 Image editing tool Photoshop GIMP Honestly, there is no tool comparable with Photoshop. I can make do with GIMP in some simple tasks but for serious “business” (like my wedding photos :D) I’ll need Photoshop anyway.

When I first moved to Ubuntu, I though I couldn’t do anything with it. But now I feel quite comfortable and “workable”. Though it still lacks some tools (like Live Writer which I’m using to post this blog) but thanks to its open environment, sooner or later, there’ll be good (and free) alternatives. (As I’m expecting ScribeFire to be sophisticated enough to replace Live Writer).

It’s high time we moved to Linux not only for the sake of free softwares but also because it has become mature enough.

Update: I have added some links to the softwares’ home page for easy reference. However, most of the Linux alternatives can be found in Ubuntu software center