FlashDevelop, Haxe import CreateJS?

我们两清 提交于 2019-12-20 02:42:08

问题


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

Anything else I have to do to make this work?

Thanks!

-Pablo


回答1:


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)




回答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.




回答3:


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

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

Thanks



来源:https://stackoverflow.com/questions/12341211/flashdevelop-haxe-import-createjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!