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-classes
Copy 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":
<compilerflag name="-swf-lib yourpath/mochi.swf"/>
Make sure the path to "
mochi.swf" is correct.
5. Compile your project, that's all.
(Besides, you can use other swf libs with haxenme similarly.)
Full source code of my test project:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HaXeNME MochiAds Test
And the demo swf proving it works:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/Tutorials/HaXeNME MochiAds Test/bin/flash/bin/HaXeNMEMochiAdsTest.swf
Links:
1. NMML File Format: http://www.haxenme.org/developers/documentation/nmml-project-files/
2. http://haxe.org/doc/start/flash#using-the-library
http://www.alexjeffery.org/programming/how-to-embed-a-swf-file-in-haxe/
http://wootfu.com/2011/08/using-mochiads-with-haxe/
http://brianin3d.wordpress.com/2010/08/04/kit-kat-toe-mochiads-with-haxe/