Simple Generic Object Pooling in AS3

For Flash and Flex, object pooling is very important for performance, also an efficient way to avoid memory leak. Although many developers should have found good way to implement pooling, I unable to google a good one fitting my needs. So here’s my simple solution.

You could find source code here:

Basically, a pool could store any kinds of object (maybe sprite, UIComponent), as long as it implements IReusable interface.

  • function cloneNewObject():IReusable;
  • function reset():void;

Basically, the pool will be set with a single object as seed (also first object), any new object will be made by cloneNewObject() function, and stored in a single array. You can put object back, and first not-in-use object in the array will be picked when asking.

Outside of the object pool, you may set one or multiple array or/and dictionary to keep references of these objects for different purpose if necessary.

Develop / Debug Apps with Playbook

Playbook tablet apps can be developed with simulator, it can also run/debug with real playbook. The full check list to start develop Playbook App with Flash Builder is here:

Using simulator is the easiest way to debug apps, but with a few limitations. It would be a little bit fast to run tablet app in the simulator. Unfortunately simulator is not free for Mac users, simulator has to be run in VMWare as guest OS, and VMware for Mac is not free (don’t know whether RIM would support the free VirtualBox in the future or not). A workaround that you could also install the simulator in another Windows or Linux PC, change simulator network setting from NAT to bridge mode, to allow connection between your development computer and simulator PC. The simulator itself need 1GB memory from your PC. If your development PC is not fast, consider a second PC to run the simulator.

Run/debug app directly in Playbook give you chance for a full test on your app in real environment, such as activate/deactivate, accelerometer, GPS location, maybe more.


To debug with Playbook, you must be authorized by RIM and create a debug token for the exact playbook. Complete the signing keys form, you’ll receive two .csj files usually in two workdays. With .csj files you can register with Flash Builder 4 or 4.5, then create a developer certificate so you could create debug tokens later(see image below).

Find your playbook PIN number About->Hardware,  you can create a debug token. Debug token would be a .bar file.

The playbook must be set with password, Security->Password, then change to development mode, Security->Development Mode. Then  upload the debug token to Playbook.

Configure App to debug with Playbook

App to run/debug in Playbook must have same author(company name), author ID created in the debug token. If not match, when you try to run/debug, Playbook will give you an error. The author ID can be found in debug token details, from Flash Builder Preference -> BlackBerry Tablet OS (for FB4) -> Signing -> Debug Tokens -> Details.


Create run/debug Configuration for Playbook

Playbook apps will be compiled and deployed either in simulator or real playbook to debug. In Flash Builder 4 (new Flash Builder 4.5 may better on this) a debug configurations must be setup (and adjust for each app project). It would be exact same for simulator and playbook, except pointing to different device with different device IP address, as well as host IP address (host IP is the IP address in your develop computer, where the simulator/playbook could connect to your develop PC. For example, if Playbook IP is 10.0.1.x, your host IP should be the IP 10.0.1.x in your computer, you can find IP addresses with ifconfig -a in Mac, or ipconfig /all|more in Windows. If your simulator run in the same development PC, host IP would be different)

When you create a new app project, please remember to check run/debug configuration for the new project, otherwise Playbook may give you errors.

App Failed to run?

It can happen sometime if your app configuration file, or your code not supported, or debug configuration incorrect, app will fail to run in Playbook, even worse, after an error happen, all apps in your Playbook would no longer able to run. You can try these if you run into trouble:

  • Check your blackberry-table.xml configuration file and debug configuration, try again.
  • Try to uninstall the app first, try again.
  • If Playbook not work properly, try to restart with the “Power Off” app.
  • If “Power Off” couldn’t run (in this case, all apps fail to run), hold the power button to restart Playbook.

Playbook App Project

Unlike Flash or Flex/Desktop AIR applications, Playbook apps must be run in simulator or real Playbook. It not worth to develop every piece of code and run that way (means compile, transfer to another place, then install, then start), which not so effective and waste lots of time.

Playbook AIR SDK has some parts such as web browser must use QNX packages, but UI could be built with Flex spark components or plain AS3 (no old MX components). Another concern most Flash/Flex team would like to develop a mobile app with one codebase and deploy in multiple OS systems,  so it would be better to separate the project into two type of projects:

  1. One standard type Actionscript/Flex project(s), to develop UI as well as some functions, with mockups/test cases to maximize development tasks.
  2. Another BlackBerry Tablet app project, with shared code/library from #1 project, mainly develop Playbook-specific functions, as well as final tests.

Update AIR 2 SDK on Flash Builder 4


The easy reliable way to update AIR 2 SDK actually you can grab Flex SDK 4.1:

Following original post on issues when updating with AIR 2 SDK package directly:

I decided to update AIR 2 on Flash Builder 4 for new features, but got some troubles.

Had a quick look on AIR 2 release notes. Downloaded the new AIR 2 SDK on my iMac and extracted on desktop.

Copy-and-paste on Mac = Fail

For my Mac (snow leopard), the folder to be updated:

  • Mac Flash Builder 4: /Applications/Adobe Flash Builder 4\sdks\4.0.0

In the release notes, Adobe recommend to use command line for Mac OS update, but I think it would be the same to copy/paste with extracted SDK. So I made a backup of 4.0.0, and overwrite directly on top of 4.0.0 folder with new AIR 2 SDK.

Then I opened Flash Builder, well, Flex SDK 4 broken.

Looked into the 4.0.0 folder, surprised to me some original files of Flex SDK 4.0.0 missing after copy-paste.

Then I redo 4.0.0 from backup, this time no longer copy with whole folder but copy files for each folder, except air folders.

Reopened Flash Builder, now I can add Flex SDK 4 successfully.

Snow Leopard File Permission @ Sign with AdobeAIRSDK.tbz2 Package

Whether there’s any difference between copy-and-paste and command line extract? I opened Terminal to see whether something special I could find. What I saw actually, all new files of AIR 2 SDK, had a different file permission flag like this one: -rw-r–r–@

A @ sign!

What’s @ sign means? “The @ sign simply means there is a resource fork added to the file, completely normal for files living in an HFS+ file system under OS X, especially Snow Leopard which even keeps compressed data in resource forks. You go jacking with Snowie’s resource forks and you will get yourself in a heap of trouble.” “This attribute is added so that it can ask for user confirmation the first time the downloaded program is run, to help stop malware. Upon confirmation the attribute should be removed and then the program will run normally.”

I tried again with command line, same as release notes, but, the @sign still exist.

What I can say, @ sign may wouldn’t cause any problem, but who knows, it better to take it out.

So here’s what I did. In Terminal jump to the sdk4.0.0 folder:

  • ls -ald@ *tbz2
  • xattr -d *tbz2
  • ls -al
  • tar jxvf *tbz2

For some reason, the @ sign come with a extended attribute value “”. Once remove this attribute value from the package, after extract all new SDK files no longer have a @ sign.

Don’t forget update project-app.xml

This is a important step but in the release notes, it belongs to “Flash Professional CS4″ section.

The problem is, each AIR project has an application descriptor file app.xml in source root folder, my AIR project created before AIR SDK update, so it was using old namespace, if you run your application for any new class, i.e. ServerSocket, it will give you an error:

VerifyError: Error #1014: Class ServerSocket could not be found.

The reason simply because old AIR project using old SDK namespace, you need update project-app.xml to:

  • <application xmlns=”″>