Using AsWing/as3 with Haxe

This simple tutorial explains how to use the powerfull AsWing GUI framework within Haxe
This tutorial covers AsWing 2.0 port HaxeAsWing and Haxe 2.09/NME 3.31, for older versions see history

Download AsWing

Setup a Test Project

Now let's start a new haxe project for testing.

  • Copy HaxeAsWing source code into your project directory.
  • Create a file Hello.hxml:
    -swf Hello.swf
    -swf-header 600:400:21:ffffff
    -main Hello
    -swf-version 9

Create a file Hello.hx:

import org.aswing.JButton;
import org.aswing.JFrame;
import org.aswing.geom.IntDimension;
import org.aswing.AsWingManager;

import flash.Lib;
import flash.display.Sprite;
import flash.display.StageScaleMode;

class Hello extends Sprite {
    public function new() {
    //reset ui to its defaults
        //create a frame    
        var frame : JFrame = new JFrame( this, "HelloApp" );
        //if you want to create a "fullscreen" interface rather than
        //draggable window with title, use JWindow instead
        frame.setSize(new IntDimension( 200, 120 ) );
        //create a button
        var button:JButton = new JButton("Hello from AsWing in Haxe!");
        //add the button to the frame
        //add the frame to the stage
        this.stage.scaleMode = StageScaleMode.NO_SCALE;
        //show it!;
    public static function main() {
        new Hello();

Now let's compile it by executing:
>haxe Hello.hxml

When everything went fine, you should have a flash file Hello.swf displaying a frame with a button in it, saying Hello!

Using Look And Feel

Old LAFs are not compatible with AsWing 2.0, but you can easily customize new default LAF as in example below
import org.aswing.UIDefaults;
import org.aswing.UIManager;
import org.aswing.plaf.ASColorUIResource;
import org.aswing.plaf.basic.BasicLookAndFeel;

class MyLAF extends BasicLookAndFeel
    override private function initComponentDefaults(table:UIDefaults):Void{  
        var comDefaults = [
            "Button.background", new ASColorUIResource(0x000000),

class Hello extends Sprite {
    public function new() {
        //create a frame
        UIManager.setLookAndFeel(new MyLAF());

This code makes the button to be black. For more information look into org/aswing/plaf/basic/BasicLookAndFeel.hx


  • use GUIBuilder application from downloaded AsWing package to design complex interfaces. Though it is a powerful tool and can produce Haxe code, last version is not fully compatible and you'll have to make this code work.
version #13841, modified 2012-04-24 04:17:28 by paling