Category Archives: Tips & Tricks

ZeroBrane Studio

For Lua development, whether it is for plain Lua or platforms such as Corona SDK, ZeroBrane Studio is an excellent open-source IDE (written in Lua) for Windows, Mac OS and Linux. I still use Sublime Text with the Corona Editor plugin but ZeroBrane Studio is my first choice for Lua development.

This IDE is updated frequently and has great support from Paul Kulchenko. To grab the latest update before a new version is released, download from the github page, and follow these steps on Mac OS:

  1. Locate ZeroBraneStudio.app in the Applications folder
  2. Right-click on the app and choose Show Package Contents
  3. Open the Contents folder, and then the ZeroBraneStudio folder
  4. Drag and drop everything(*) inside the (github) ZeroBraneStudio folder into the above folder inside the app

* Actually not all files are needed, see an example of files and folders to drag over in the following image:

 

If you have made changes to a theme or configuration (such as tomorrow.lua in the cfg folder), make sure you have a backup copy before replacing everything as described above.

Download the IDE here: http://studio.zerobrane.com

To show Corona SDK reference from right-clicking on a keyword in the editor, add the following code to the end of your user settings (user.lua) found under the Edit | Preferences menu:

Add showreference.lua from ZeroBranePackage to the ~/.zbstudio folder if it’s not there already. Quit and relaunch the IDE to see the update.

Class browser

In Flash MX 2004, one thing I wished it had is a class browser. But with all the new features in this release, we can’t have everything on our wishlist all at once, can we?

Here’s a little tip on how to make your own “class browser” with the Project panel:

Because all the classes have external .as class definitions inside the folder:
[Flash installation folder]enFirst RunClasses, we can add these to the Project panel and browse the classes from there. Double-clicking on an .as file from this list opens up the class definition in the Script window (in the Pro version only):

ClassBrowser.gif

To save you all the work of browsing through the folders and making your own project, download it here: ClassBrowser.flp

abstract class

Since ActionScript 2.0 does not have the “abstract” modifier, here’s one way to create a class that acts like an abstract class, by making the constructor private:

When the following statement is compiled, the compiler will complain that one can’t instantiate from this class because the constructor is private:

var o:PretendToBeAbstractClass = new PretendToBeAbstractClass();

Although the constructor is private, but because it behaves as protected, you can still extend this class:

class MyClass extends PretendToBeAbstractClass {
}

What is missing is the compiler does not actually know what an abstract class is; therefore there won’t be any warning messages.

As I mentioned in the last post, you can get around all the type-checking at runtime, and even instantiating an “abstract” class at runtime like this:

var o = new _global["PretendToBeAbstractClass"]();

Or even access “private” properties from it:

trace(o.somePrivateVar);

Obviously these actions defeat the purpose of strict-typing, but it is possible (until runtime type-checking is implemented).

Singleton

Here’s one way to implement a Singleton in ActionScript 2.0:


The count property is for keeping count of the number of Singleton objects referenced (obviously it is not aware of destroyed objects), and is not really a necessary member of the Singleton pattern.

To use this class, one would write something like this:

var s1:Singleton = Singleton.instance;
var s2:Singleton = Singleton.instance;

Now s1 and s2 are the same instance of the Singleton class.