Using MochiAds in haXe - April 17th, 2009
I recently created a flash game using haXe and swfmill. Now I wanted to use both MochiAds version control and MochiAds leaderboards in the game.
For the version control I simply added a new game from the MochiAds dashboard, after logging in, and followed the simple steps. No need to get more into this part. It's very simple really, and works fine in haXe.
For the leaderboards part it got a little more difficult.
First off I downloaded the latest MochiAds API (can be found on the dashboard under "Downloads") and found a ActionScript 2.0 version and one 3.0 version of the API. No haXe version. First I looked at the code to determine how long it would take to port it to haXe. I decided way too long.
To cut things a little shorter, I simply did like this instead:
- Unzip the downloaded MochiAds API. Open cmd and navigate to that folder, or create a batch script in it.
- Execute this command:
compc -source-path . -output mochi.swc -include-classes mochi.as3.MochiAd mochi.as3.MochiDigits mochi.as3.MochiScores mochi.as3.MochiServices
or
compc -source-path . -output mochi.swc -include-sources .Notes:
- You can look up compc syntax here
- If you don't have the free Flex SDK installed, get it at adobe.com
- If you don't have the flex folder in your PATH environment variable change 'compc' to the actual path
- If everything worked fine you should have a mochi.swc file in the same folder. Rename it 'mochi.zip' and extract the 'library.swf' found inside it.
- To get the required haXe files execute this command (like you did above):
haxe --gen-hx-classes library.swf
- This should create a new folder called 'hxclasses' and inside it a 'mochi' folder. Copy this folder to your sourcepath.
- Now we want to use the created 'library.swf' file as our -swf-lib file. If you already have a flash file as your -swf-lib file, don't worry, so did I.
- Simply create a new flash file with swfmill with xml tags something like this:
<clip id="assets" import="assets.swf"/> <clip id="mochi" import="library.swf"/>
- And use the resulting flash file as your -swf-lib
That should be all. Now you should be able to use all MochiAds features in haXe. Enjoy!
If you are having any trouble or have any questions feel free to send me an e-mail at viktor.hesselbom at gmail.com
- Viktor Hesselbom