by Josh Tynjala
IntelliJ IDEA has recently become one of the more popular development environments available to ActionScript developers. While Jetbrains hasn't fully optimized their IDE for the Apache FlexJS SDK yet, it only requires a few tweaks to reconfigure a module to transpile ActionScript to JavaScript and run it in a web browser.
If you'd prefer to use an IDE instead of running the asjsc
compiler on the command line, IntelliJ IDEA is now a great way to get started.
For this tutorial, you should install IntelliJ IDEA Ultimate. A free trial is available.
Additionally, you should install Apache FlexJS 0.7 or newer. Use the Apache Flex SDK Installer to download it.
First, let's add Apache FlexJS as an SDK to IntelliJ IDEA. We'll need to do that in the IntelliJ IDEA preferences window.
Select the File menu → Project Structure....
From the list on the left side of the Project Structure window, choose SDKs under Platform Settings.
In the middle column, press the + (plus sign) button, and choose Flex/AIR SDK.
Select the directory where you installed Apache FlexJS, and press the OK button.
In the list on the left of the Project Structure window, select the Libraries item under Project Settings.
In the middle column, press the + (plus sign) button, and choose ActionScript/Flex.
Inside the Apache FlexJS SDK, select js/libs/js.swc
.
Press the + (plus sign) button to add another SWC to this library. Then, select frameworks/libs/Language.swc
inside the Apache FlexJS SDK, and press the OK button.
Give the library a name that you can remember, such as flexjs-js-libs
.
Press the OK button in the Project Structure window to finish.
Everything should now be ready to create a new module that uses the Apache FlexJS SDK.
Next, we'll create a new IntelliJ IDEA module using Apache FlexJS.
Open the File menu → New → Module...
From the list on the left side of the New Module window, choose Flash.
For the Target platform, choose Web.
Ensure that Pure ActionScript is not checked.
For the Output type, choose Application.
For the Flex/AIR SDK, choose the Apache FlexJS SDK that you added in the previous section.
Check Create sample app and enter HelloIDEA.as
for the name.
Ensure that Create HTML wrapper template is not checked.
Press the Next button.
Enter your Module name. For this example, let's choose HelloIDEA
.
Press the Finish button.
The new module has now created, but we have a couple more things to configure.
Next, we'll tweak a few of the module's settings to make it work properly with Apache FlexJS.
Open the File menu → Project Structure....
In the list on the left, choose Modules under Project Settings.
In the middle column, open your module's branch, and select it.
In the General tab, set the Output folder to your module's main directory. This will make it easier to run the transpiled code directly from IntelliJ IDEA.
Navigate to the Dependencies tab.
Press the + (plus sign) button and choose Project or Global Library....
Select the flexjs-js-libs
library that we defined earlier, and press the OK button.
In the Linkage column, change the flexjs-js-libs
linkage to External.
Navigate to the Compiler Options tab.
From the Locales setting, remove en_US.
Near the bottom, add the following arguments to Additional compiler options:
-js-output-type=jsc -load-config+=/ide/IDEA/intellij-config.xml
Replace
with the real location of the SDK on your file system.
Open HelloIDEA.as
in src
directory of your module.
Delete the entire contents of this file, and replace it with the following code:
package
{
public class HelloIDEA
{
public function HelloIDEA()
{
var button:HTMLButtonElement = document.createElement( "button" ) as HTMLButtonElement;
button.innerHTML = "Press Me";
document.body.appendChild( button );
button.addEventListener( "click", button_clickListener, false );
}
private function button_clickListener( event:MouseEvent ):void
{
alert( "Hello World" );
}
}
}
You'll notice, as you type, that IntelliJ IDEA suggests classes like HTMLButtonElement
and its members like innerHTML
and addEventListener()
automatically. We can use web browser APIs in ActionScript!
Create a file named debug.html
in the root of the project. Include the following markup that references the JavaScript files from the js-debug
directory:
HelloIDEA Debug Build
A debug build loads each ActionScript class at runtime using the Google Closure library. The dependency manager is loaded by including the base.js
file:
Another file, HelloIDEA-dependencies.js
, tells the dependency manager which classes from the project are needed, and the order that they should be loaded:
In the , another script block instantiates the
HelloIDEA
class. This will start the application.
See Hello World: How to set up Apache FlexJS to transpile ActionScript to JavaScript for an example of HTML for a release build.
Open the Run menu → Edit Configurations....
Press the + (plus sign) button and choose JavaScript Debug.
Set the Name to HelloIDEA
.
Next to the URL, press the ... button and choose the debug.html
file that you created in the previous section.
For the Browser ensure that Chrome is selected. It may be called Default.
In the Before launch section, press the + (plus sign) button, and choose Make.
Press OK in the Run/Debug Configurations window.
Open the Run menu → Debug..., and choose the HelloIDEA configuration. Google Chrome should open.
You should see a webpage that looks something like this:
Try pressing the button to see what happens!
-source-map
compiler option, and use your web browser's built-in debugging tools instead. Technically, IntelliJ IDEA supports source maps too, but it incorrectly assumes that ActionScript must be debugged by running a SWF file.
Open the Run menu → Debug..., and choose the HelloIDEA configuration. Google Chrome should open.
In IntelliJ IDEA, open js/out/bin/js-debug/HelloIDEA/HelloIDEA.js
. This is one of the generated JavaScript files.
Try adding a breakpoint on the line where alert()
is called in HelloIDEA.js
.
Press the button on the page, and the debugger in IntelliJ IDEA will take over.
To print debug messages to the console in IntelliJ IDEA, you may use the standard ActionScript trace()
, or you can call JavaScript functions like console.log()
or console.error()
.
Try changing the button's click event listener to print a debug message instead of showing an alert:
private function button_clickListener( event:MouseEvent ):void
{
trace( "Hello World" );
}
Would you like to learn more about transpiling ActionScript? Please become a patron, and support the creation of a whole library of detailed, step-by-step tutorials — including video tutorials! Let's work together to teach the next generation of ActionScript developers.