Adding Mochi Ads & Scores to a Stencyl Game

Mochi Media is one of the most popular ways for Flash game developers to make money with their games using  their in-game ads product Mochi Ads. Mochi is also a one-stop solution for game analytics, achievements, leaderboards, and virtual currency.

StencylWorks is an easy way to visually create Flash and iOS games for non-coders and programmers alike. Starting with StencylWorks 1.2, developers can add Mochi Ads and scores to their games in just a few minutes!

Download the Sample Game 

(Unzip and place “Balloons” folder under the StencylWorks “games” directory.)

This balloon-popping game records how long it took for you to beat the (only) level. We’ll use Mochi to record the score on a leaderboard and show an ad after clicking the reset button.

Sign up on Mochi’s Site

Sign up on Mochi’s site if you haven’t done so already.

Add a Game on Mochi’s Site

Each game you wish to support you must add to Mochi’s site.

1) Click the “Add Game” tab

2) Fill in the page as shown below and submit.

Stencyl games don’t function with Live Updates at this time.


Locate the game’s Mochi Game ID

Every game has a unique game ID, so Mochi can identify it and store all of its data in one place. You can find the Game ID box on the game’s page.

To reach a game’s page, visit the Dashboard and click on the game’s name.


Enter the Mochi Game ID in to your game

Now that you’ve set your game up on Mochi’s site, you need to enter in the game’s ID so it can establish a connection with Mochi’s servers to present ads and scores.

1) Open your game in StencylWorks.

2) Click on Advanced Settings under the Game Center tab. Enter the game’s Mochi Game ID.

3) Save your game.


How to Display a Mochi Ad

Displaying an ad is simple. Add the “show Mochi ad” block precisely at the time you wish to show the ad.

For our Balloon game, we want to show an ad after clicking the reset button.

1) Open up the “MochiAd” behavior under Game Center > Logic > Scene Behaviors

This behavior instructs the game to display the ad right away. Our approach in this game is to set up a separate scene exclusively for displaying the ad, so that the ad doesn’t disrupt regular gameplay.

2) To make this behavior work, we need to attach it to a scene. Click “Attach to Scene” and choose “Ad Scene.”

3) Save and run the game. Notice the ad now appears after you click the Reset Button.

(Get an error? Jump to the bottom. Ad is a little slow in showing up? That’s normal when testing offline.)


How to Submit a Score and Display a Leaderboard

Displaying a leaderboard requires setting up the leaderboard first on Mochi’s site.

1) Visit the Scores page for your game by clicking “Scores” in the sidebar.

2) Click “Add Leaderboard” – it’s a small button on the right-hand side of the page.

3) Fill in an appropriate title. Leave the rest of the fields as-is and submit.

4) Click on the “actionscript code” link on the next page.

5) Look for “Leaderboard Id” and copy it to your clipboard – this is what you’ll enter in to StencylWorks.

6) Now, open up the “MochiScores” behavior under Game Center > Logic > Scene Behaviors.

7) Locate the “submit score” block that’s already placed. Provide the Leaderboard Id you found in Step 5. For this game, we are recording how many seconds it took for you to pop all 40 balloons.

8) To make this behavior work, we need to attach it to a scene. Click “Attach to Scene” and choose “First”

9) Save and run the game. The game will now show the leaderboard after finishing the level.

(Get an error? Jump to the bottom.)


What’s Next?

Now that you’ve learned how to add scores and ads to your games, what’s next?

Get Your Game Approved by Mochi

You won’t start making money off those ads until your game’s been approved by Mochi. To get approval, you need to test game locally to present an ad and fill out your game profile on Mochi’s site. Mochi approves most games within 24 hours.

Let Mochi Distribute Your Game

Mochi not only maintains an ad network and APIs for its games, it also maintains a distribution network for Flash games, so your game can reach more players. It does this by offering feeds and embeddable “arcade” widgets that website owners can embed in their sites to present games relevant to their site.

To participate in this program, visit your game through the Dashboard and locate this box.

Troubleshooting: What to do if ads and scores do not show up, or if you receive an error.

If you are testing locally, and want to be able to see ads or scores, you may need to do the following.

Add the location of your development files to your global security settings in the Adobe Flash Player Settings Manager. This way, you can give all SWF files in this location local-trusted access, allowing access to both local and remote data.

The folder you want to add is the entire StencylWorks folder. This will catch everything underneath it, including the game itself. If you’ve chosen a custom workspace, you also need to add the folder for that.


Discuss this Article on our Forums!