How do you add a third-party Haxe library to your project?

252 views
Skip to first unread message

howwi...@gmail.com

unread,
Dec 9, 2013, 5:16:03 PM12/9/13
to haxe...@googlegroups.com

I'm starting to transition from AS3 to Haxe in my spare time, and I'm currently trying to import a third-party library for Haxe. In this case, it's a Starling port: http://lib.haxe.org/legacy/p/starling. It looks to me like swfs essentially replace swcs in Haxe, and the folder contains a starling.swf, not a starling.swc. The IDE I'm using is FlashDevelop.

So I added a folder in my project's solution called "libs", and I added starling.swf into that folder. I can expand starling.swf in the solution explorer, and it shows me things like the classes it has in it, for example. So I right-clicked on it and selected Add To Library. But now if I try to build what's effectively a Hello World project with that swf being added as a library, the build process takes several seconds, then fails with no errors. I've already made sure the target platform is Flash Player 11.1, as opposed to the JS default.

The library itself seems to be endorsed by the Haxe community, so I don't think it's just corrupted or anything. But I have tried Googling how to add a library to a Haxe project in FlashDevelop without much success. What am I doing wrong here? Thanks.

postite

unread,
Dec 9, 2013, 5:20:16 PM12/9/13
to haxe...@googlegroups.com
hi !,
it seems you are using a haxe2 lib ( the legacy in the url )  are you using haxe3 ? 

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

postite

unread,
Dec 9, 2013, 5:24:07 PM12/9/13
to haxe...@googlegroups.com
did you try this lib 

you can just install it using haxelib git 


Le 9 déc. 2013 à 23:16, howwi...@gmail.com a écrit :

John Robertson

unread,
Dec 10, 2013, 12:05:03 AM12/10/13
to haxe...@googlegroups.com
Looks like it is Haxe 3.  Thanks for catching that.

The starling subdirectory in the github one is empty (there was a link to another github project in the directory in github), but I did see a Starling.swf in haxelib.  When I tried adding that though, the same issue arose.  Some of this is new ground for me though, so I'm not sure if I'm following everything, sorry. 


You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

Juraj Kirchheim

unread,
Dec 10, 2013, 4:00:42 AM12/10/13
to haxe...@googlegroups.com
Typically you will use haxelib to use 3rd party libraries.

For projects that are on the central server, you can use `haxelib
install <libName>`. For projects that are on a git repo, you can do
`haxelib git <url>`. Once a library is installed, you can add it with
`-lib <libName>`. In FlashDevelop you can do that in the Project
Properties by either adding it the Additional Compiler Options, or
just adding libName to the Libraries.

In the output panel you should see how FD invokes Haxe with `-lib
libName`. The starling library should be able to add the Starling.swf
to the compilation, but as it says at the bottom of the project page,
a bug may be preventing that, in which case you will need `-swf-lib
Starling.swf`.

In any case, there are certain types of errors that FlashDevelop
doesn't send to the Results panel, only the Output panel. If
compilation fails without visible feedback, always check the Output
panel. The type of errors that you will find there are errors that
don't correspond to any Haxe source file (this can be achieved with
AS3 also if you manage to misconfigure your mxmlc) but rather the
compilation process as a whole (the -main file cannot be found, no
output specified or whatever).

Regards,
Juraj

Philippe Elsass

unread,
Dec 10, 2013, 4:30:29 AM12/10/13
to haxe...@googlegroups.com
As other people said: use haxelib for 3rd party libraries if they exist - saves you a lot of troubles.
 
For FlashDevelop you better specify the library name in Project Properties > Compiler Options > Libraries.
Adding it to Additional Compiler Options will technically work too but you will be missing some features like auto-import and go to definition.
Philippe

John Robertson

unread,
Dec 10, 2013, 11:52:03 PM12/10/13
to haxe...@googlegroups.com
Thanks.  It looks like it's going ahead and adding the library at this point, but if I so much as say, "import starling.core.Starling;" it fails to build with this in the Output window:

C:\HaxeToolkit\haxe\lib\starling\git\haxelib\Starli...@starling.core.Starling:1: character 0 : Same field name can't be use for both static and instance : context
C:\HaxeToolkit\haxe\lib\starling\git\haxelib\Starli...@starling.core.Starling:1: character 0 : Same field name can't be use for both static and instance : contentScaleFactor
C:\HaxeToolkit\haxe\lib\starling\git\haxelib\Starli...@starling.core.Starling:1: character 0 : Same field name can't be use for both static and instance : juggler
C:\HaxeToolkit\haxe\lib\starling\git\haxelib\Starli...@starling.core.RenderSupport:1: character 0 : Same field name can't be use for both static and instance : clear
Build halted with errors (haxe.exe).

The only thing I saw on the Internet about that was just in a situation when somebody was mismatching package names when trying to initialize a Starling instance, whereas my import statement is enough to break it:

package ;

import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.Lib;

import starling.core.Starling;

class Main
{
   
    static function main()
    {
        var stage = Lib.current.stage;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        // entry point
    }
   
}

Hopefully this is the last little issue with getting it to import right.

John Robertson

unread,
Dec 16, 2013, 10:56:25 PM12/16/13
to haxe...@googlegroups.com
Sorry, I've been getting really bogged down with Christmas and a deadline coming up at work.  Thank y'all very much for your help.  As soon as I get a chance, I'll look at it some more and see what I can find about this last little hurdle.  But y'all got me past the main issue.  Thank you.
Reply all
Reply to author
Forward
0 new messages