Search code examples
javascripthaxecocktail.js

Haxe - Class not found : Main


I try to use haxe and cocktail for the first time. I follow this tutorial : http://www.silexlabs.org/haxe/cocktail/tutorials/getting-started-with-cocktail/

Main.hx

import js.Lib;
import js.Dom;

class Main
{
    static inline var ICON_COCKTAIL_PATH:String = "assets/icone_cocktail_blanche_ombre.png";
    static inline var ICON_HAXE_PATH:String = "assets/icone_haxe_blanche_ombre.png";

    static function main()
    {
        #if !js
        //init cocktail and load the "index.html" file in the bin folder
        cocktail.api.Cocktail.boot();
        #end

        //html and css loaded
        Lib.window.onload = function(e) new Main();
    }

    public function new()
    {
        // get the image node
        var image:Image = cast Lib.document.getElementById("icon");

        // create interactivity
        image.onmouseup = function(event:Event) {
            // if image source is cocktail icon, change it to Haxe one
            if (image.src.indexOf(ICON_COCKTAIL_PATH) != -1)
                image.src = ICON_HAXE_PATH;
            // if image source is not cocktail icon, change it back to cocktail
            else
                image.src = ICON_COCKTAIL_PATH;
        }
    }
}

compile.hxml

-main Main
-cp ../src
-js ../bin/Main.js

I have following folder structure:

\Helloworld
    \bin
        \assets
            \icone_cocktail_blanche_ombre.png
            \icone_haxe_blanche_ombre.png
        \app.css
    \build
    \src
        \index.html
        \Main.hx
    \compile-js.hxml

But when I try to compile :

haxe compile.hxml 
Class not found : Main

Thanks


Solution

  • I think your compile.hxml should look like this. Note the path to src folder. I believe this is related to hxml file location.

    -main Main
    -cp src
    -js bin/Main.js