HaXeNME (http://www.haxenme.org) is an open source, cross platform haxe lib for developing games using a Flash like api. Just try it if you don't know it. If you hope to write once and compile to flash/html5/cpp/ios..., HaXeNME should be your first choice. I never tried to use mochiads with haxenme, though I know it is totally possible. Since some one PMed me for this topic, I did a quick research and want to share it here as a reminder for future reference.
Note: this is not a detailed step-by-step tutorial for newbies, just a reminder. I assume you have some experience of developing with HaXeNME using FlashDevelop (http://www.flashdevelop.org). However, if you have problems, feel free to post it here below.
The general steps for using mochiads with HaXeNME:
1. Download mochi api source code and compile all the AS3 source files into a "mochi.swc", unzip the swc file, rename the "library.swf" to "mochi.swf".
2. Generate the haxe source files needed for compiling your NME project:
haxe.exe -swf mochi.swf --no-output -swf-lib mochi.swf --gen-hx-classesCopy the genetated "mochi" folder (in its "as3" subfolder you should find lots of haxe files, such as "MochiAd.hx", "MochiCoins.hx", ...) into your project's "src" folder.
3. Import the mochi apis in your haxe project's main class:
import mochi.as3.MochiAd; import mochi.as3.MochiServices;To show pregame ads, for example, using the following code, similar to AS3:
MochiServices.connect("60347b2977273733", root); MochiAd.showPreGameAd( { id:"60347b2977273733", res:"640x580", clip: root} );
4. Edit your project's "application.nmml", add the following line to force the haxe compiler to link "mochi.swf":
5. Compile your project, that's all.
(Besides, you can use other swf libs with haxenme similarly.)
Full source code of my test project:
http://wootfu.com/2011/08/using-mochiads-with-haxe/
http://brianin3d.wordpress.com/2010/08/04/kit-kat-toe-mochiads-with-haxe/
Thanks for posting this information. It's named as simple, but it's amazing tutorial.
ReplyDeleteIt really helped me to get my work done which otherwise could have consumed lot of my time to find this technique.
I was getting some odd read-only errors until I passed in the as3_native flag to the haxe compiler. You can do this from the project's NMML file too, like this.
ReplyDeleteSource: https://code.google.com/p/haxe/issues/detail?id=992
Looks like it stripped out the actual content. :/
DeleteReplace the square brackets with angled ones, and you'll get what you need to put into the NMML file.
[haxeflag name="as3_native" /]
[haxeflag name="-swf-lib" value="mochi.swf" if="flash" /]
Hopefully, it goes through this time...
Great! Thank you very much.
ReplyDeletethank you for the valuable info dose this work for haXePunk ?
ReplyDeleteNever tried but it should work with any NME based projects.
Deletegood job man.
ReplyDeleteone question, I can compile it. using Haxe for android?
I think that won't work, although I never tried. HaXe for Android will compile everything to native code, but Mochi doesn't provide service for native applications such as Android & IOS apps.So I think this way only works for HaXe targeting Flash.
Delete