3

I just started trying out Haxe to make a web-app, and I would like to use CreateJS, which has a Haxe extern lib thingy. I'm using FlashDevelop as my IDE.

So I created a new Haxe JS project in FlashDevelop, and installed CreateJS with "haxelib install createjs". Thougg now I try to add an import to my Main.hx, but it doesn't work. My import looks like: "import createjs.easeljs.Ticker;" (got that from an example, just copied it but didn't work :s) I also added a new map "lib" to my project, in which I added the createjs stuff.

The error I get is: src/Main.hx:3: characters 0-31 : Class not found : createjs.easeljs.Ticker

enter image description here

Anything else I have to do to make this work?

Thanks!

-Pablo

The Oddler
  • 6,314
  • 7
  • 51
  • 94

3 Answers3

6

The way Haxe externs usually work is:

  1. You include the original Javascript manually*. In your case, you add the tags pointing to the CreateJS javascript ( into your HTML file.

  2. The 'extern' files are used so that Haxe knows the other files are there, and knows what methods can be called, properties changed etc. It also helps keep the auto-complete fully functional and useful.

  3. If the externs are kept in a library, you need to install that library (haxelib install createjs) and then you need to include that library in your build. I do this by adding -lib createjs to the hxml build file. Flash Develop can do this by opening Project->Properties->Compiler Options and adding "createjs" to the Libraries list.

  4. In your Haxe file, you use the "include" statements, like you have above.

From your description above, I think you're missing the bit in step 3 where you include the library. I'm not a Flash Develop user, so I'm not sure if it's different at all, but it looks like in your follow up answer you've copied some of the *.hx files from the 'createjs' haxelib, just enough to make it compile. If you add the '-lib createjs' line to your hxml build file though, you shouldn't need these anymore.

Hope this helps you get started, let me know if you get stuck and I'll try update my answer.

(*) an exception to this is some libraries include the Javascript for you. An example is when you use js.JQuery in the Haxe standard library - this includes the raw javascript for you. Most libraries you'll have to add the scripts yourself though.

(Edit: added instructions for adding libraries in Flash Develop thanks to comment)

Jason O'Neil
  • 5,908
  • 2
  • 27
  • 26
  • Ok, I finally got to testing this out, and got it to work! The FlashDevelop way of doing the "-lib createjs" thingy is: go to the menu project->properties->compiler options-> add "createjs" to the Libraries list. My html & folder structure now looks like this: http://i.imgur.com/8nqYa.png – The Oddler Sep 10 '12 at 20:15
  • That's good! Glad you got it to work... I might edit my answer to show how to add libraries in flash develop. – Jason O'Neil Sep 11 '12 at 01:59
2

In FD goto Project->Properties then to the Compiler Options tab there you can add each required lib you installed with haxelib and don't need to copy the lib source into your project source tree. This will only be useful in case you need to modify the lib.

0

Ok I played around a bit more with the maps and now it's fixed, here's how it looks now:

enter image description here

If anyone has some more info about externs, and how they work, this would still be appreciated!

Thanks

The Oddler
  • 6,314
  • 7
  • 51
  • 94
  • I needed more than the text allowed in a comment to answer, so see my answer below. It looks like you need to include '-lib createjs' in your build, which will include all the externs in the createjs library for you. Hope this helps, Jason – Jason O'Neil Sep 10 '12 at 02:08
  • 2
    As Axel pointed out, you don't need to copy these files in your project, but you need to tell FD that you want to use createjs library: Project Properties > Compiler Options > Libraries > add 'lib' in the list. However if you really want to copy classes in a /lib directory you must add this /lib directory to the classpath: Project Properties > Classpath – Philippe Sep 10 '12 at 07:09