Saturday 20 December 2008

Editing/Authoring Actionscript 3 Classes in IntelliJ IDEA

I wanted to see whether it was viable to use IntelliJ 8 as an IDE for creating complete Flash applications (for writing Actionscript). By default, the application allows you to create Flex applications and creates a "HelloWorld" app to get you started. But at first it was unclear how I could write AS3 classes and compile them without jumping over to flash or using FlexBuilder.

I spent some time today dealing with issues regarding certain flash Objects (namely the Stage) being "null" and after some reading, I discovered this was to do with timing - I read around online and after looking in many places, I pieced together this mxml file:

This replaced the HelloWorld.mxml that IntelliJ provided and it does two things:

1. Waits until "applicationComplete" (so the 'stage' exists).

2. Runs a function called init(), this instantiates and places it on the stage (as a 'raw' child element). Once shell has been instantiated, init() is run and this can do whatever you like really - instantiate other classes, place objects on the stage, etc.

IntelliJ will use the Flex SDK's compiler to 'build' all of your project .as files; all you need to do is tell it where to find the Flex 3 SDK (in Leopard, it was installed by default in: /Applications/Adobe Flex Builder 3 Plug-in/sdks)

Once you've got some code written in the shell, you can use the IntelliJ debugger to run the app, inspect trace statements and so on. Although it's not quite as easy to "get up and go" with IntelliJ as it is with the FlexBuilder plugin (or application), it still makes authoring AS3 possible using IntelliJ.

Example (will trace out the stage width and height):

Hope this is useful to someone who had wanted to know how to use IntelliJ as an Actionscript IDE and who was finding the same issues I had been running into.

No comments: