R. Espinosa

Default.

  1. Why .gitignore is not working?

    Magic from the past.

    git rm -r --cached

  2. Interactive Globe: Small Arms Imports & Exports
  3. Freaking awesome!

    Freaking awesome!

  4. An Introduction to HaXe: Multiplatform Programming

    Haxe: Multiplatform Progamming

    HaXe (pronounced hex) is a multiplatform open source programming language, which means that our haxe code can be compile into C++, C#, Flash (.swf), NekoVM, PHP, JavaScript and soon even Java. In simple words, make’s your application works on web, desktop or mobile such as Android, iOS, Windows Mobile, webOS and more. It’s has a familiar syntax for those who already code in Actionscript, PHP, Java and/or Javascript; and like Java, is strictly typed with tight type checking, this allows you to check for mistakes before testing in your browser.

    Installing HaXe

    The simplest way to install HaXe is through the automatic installation for Windows, OSX or Linux. Theres also the manual installation for the adventurous ones, where you will have to compile from the source code.

    The next step is to set up your favorite IDE, I personally prefer Sublime Text. There’s a list for all the IDE plugin that supports Haxe highlighting and (in some cases) even building methods.

    Getting Started

    In order to see the advances on-the-fly we’re going to use Flash (.swf) as target platform.

    Let’s create a “Hey World” folder, from there, create a “Main.hx” file in a new “src” folder which is going to be our Main in the source folder.

    Main.hx

    
    class Main
    {
        public static function new()
        {
            trace(“What’s up world?”);
        }
        public static function main()
        {
            new Main();
        }
    }
    

    Now, let’s create a build.hxml in our root folder (“Hey world” if you’re awesome).

    build.hxml

    
    -swf bin/heyworld.swf
    -main src/Main
    

    Now, if you install HaXe well, in order to compile you just have to double-click the build.hxml file. If i’ts well done you will see a new file in the bin folder called “Hey World.swf” that shows a “What’s up world?” message in the top of the program.

    Into graphic

    Now, having created the inevitable “hello world” application let’s go graphic. Wrap our Main.hx file and change replace it for this.

    Main.hx

    // Import a specific library, just like in AS
    import flash.display.MovieClip;
    
    class Main
    {
        // Variable declarations
        private var mc:MovieClip;
        // Constants declaration
        private static inline var COLOR:Int = 0xFF33FF;
    
        public function new()
        {
            doGraphics();
            trace(‘Graphics done!’);
        }
        
        public function main()
        {
            new Main();
        }
    
        public function doGraphics()
        {
            // Attach the MovieClip to the scene 
            mc = flash.Lib.current;
            // Access to the MovieClip graphics
            mc.graphics.beginFill( COLOR );
            mc.graphics.moveTo(100, 50);
            mc.graphics.lineTo(100, 40);
            mc.graphics.lineTo(100,100);
            mc.graphics.lineTo(40,100);
            mc.graphics.endFill();
        }
    }
    

    Now, compile with build.hxml and you will see the polygon in our scene. Easy, right? But in HaXe we are talking about a language that makes possible to compile to various target so let’s grab our build.hxml and add a line.

    build.hxml

    
    -swf bin/HeyWorld.swf
    -neko bin/HeyWorld.exe
    -main src/Main