Neash/NME 0.8 released

While this blog may have been quiet, I have been busy. The next version of Neash and NME has been released on haxelib, making it very easy to upgrade. Some cool features include:

  • Fonts
  • Filters (some)
  • Bitmap Caching
  • Improved opengl speed
  • SWF reading/playing
  • Scroll rects (axis aligned)
  • Haxe 2.0 upgrade
  • But perhaps an introduction is in order. The purpose of Neash is to allow you to create programs that run on both flash and also natively, say as a downloadable program. You start with a simple (or complex) haxe program, targetting flash.


    import flash.display.Sprite;
    import flash.display.Shape;

    class Simple extends Sprite
    {

    public function new()
    {
    super();
    flash.Lib.current.addChild(this);

    // creating a new shape instance
    var circle:Shape = new Shape( );
    // starting color filling
    circle.graphics.beginFill( 0xff9933 , 1 );
    // drawing circle
    circle.graphics.drawCircle( 0 , 0 , 40 );
    // repositioning shape
    circle.x = 80;
    circle.y = 80;

    // adding displayobject to the display list
    addChild( circle );
    }

    static public function main()
    {
    new Simple();
    }
    }

    And you get a SWF that renders something like this. This works well in a browser, but what if you wanted to distrubute this as a stand-alone exe? You would of course use one of the may flash-to-exe tools around. These all, one way or another, involve packaging up the flash runtime, and this has licensing implications. Also, it can be difficult to add DRM or other native extensions to the code. So the alternative offered here is to compile it to neko!

    There are 3 simple steps for compiling to neko. 1. Get the libraries, 2. create the compiler command-line and 3. some very minor source code mods.

    1. Getting the libraries. Simply use the “haxelib” tool that comes with haxe to download and install the “NME” and “Neash” libraries. From the command (shell) prompt, type: haxelib install nme followed by haxelib install neash
    2. Create the compiler command. Rather that typing haxe -main …… every time, you can create a “.hxml” file that contains the commands, then you can simply use haxe file.hxml. The hxml file contains flags or key-value pairs of command-line arguements. You can also use the “–next” to compile to more than one target from the single invovation of haxe.

      To use neash, you will need the nme and neash libraries. To add these, you can use the command-line options “-lib neash” and “-lib nme”. For the neko target, you will also need to redirect the “flash” code to use “neash” instead. This is easily done with the “–remap flash:neash” command.

      So a hxml file that targets both flash and neko looks something like this:

      -main Simple
      -swf Simple.swf
      -swf-version 9
      -swf-header 640:480:100:334433
      -lib neash
      -cmd echo SWF done
      
      --next
      -main Simple
      -neko Simple.n
      --remap flash:neash
      -lib nme
      -lib neash
      -cmd echo Neko done
      

    3. Source code mod. You need to do some very minor modifications to run the neko version using neash. Specifically, you need to call “Init” and “Run” and the first and last things you do in your main routine. eg:

         static public function main()
         {
            neash.Lib.Init("Simple",640,480); 
            neash.Lib.SetBackgroundColour(0x334433); 
      
            new Simple();
      
            neash.Lib.Run(); 
         }
      


      Currently there is no way to get the command-line flash header data into the neko programme. The neash calls are perfectly safe under flash, so it is safe to include these in both flash and neko projects. However, you will then need “-lib neash” when compiling your flash version. The alternative is to have some “#if neko” directives in the static main routine, and carry on normally from there.

    So running haxe on this hxml file will produce both “Simple.swf” and a “Simple.n” files. You can run neko Simple.n to run the neko program, producing much the same result. You can use neko Simple.n -opengl to run with opengl acceleration – although that will no be much use in the simple case.

    All these project files, along with many others, can be found in the “samples” area of the neash library that you get when you use haxelib to install neash.

    This entry was posted in Blog and tagged , , . Bookmark the permalink.

    Leave a Reply

    Your email address will not be published. Required fields are marked *