MochiAds Support Center

Developer Support

1.0 MochiAds API Documentation

This is a simple step-by-step guide to getting MochiAds working with your Flash game. Click the links below to skip to any part of this document. The first two sections describe all that is required to get your ads running.

1.1 Prerequisites:

Before you get started, make sure you have done the following:

  1. Sign up for a MochiAds account on www.mochiads.com
  2. Log in and add a new game to your account.
  3. Download the MochiAds include file ZIP package.
  4. Choose your code options and copy the MochiAds in-game code.

1.2 The MochiAds Codes:

Figure a: The MochiAds ZIP package folder structure.

You need two things for MochiAds to work properly in your game -- The MochiAds include file, and the in-game code.

The include file contains the ActionScript code that your game will reference to display your ad. You will never need to edit this code. You just need to make sure that it is in the proper location so that it is imported or included when you publish or compile your game. You only need to do this once for each game, no matter how many ads you show in the game.

The in-game code is the code you paste into your game to display the ad at a specific point in the game. This may be placed in a specific frame on the main timeline of your movie, or called when a specific event is called in your game code. Depending on how you authored or programmed your game, where you place this code will differ. Just remember, when you make the call to MochiAds, that's when the ad will show.

Include File Installation:

Figure b: Typical MochiAds source files.

The MochiAds ZIP package contains the include code necessary for your game. UnZIP the package to a location on your hard drive. If you browse to that location, you will see a group of folders (fig.a).

Make sure to read the README.TXT file for information regarding the latest release of the Mochiads file include.

Each folder in the package corresponds to a particular coding environment. It's up to you to choose which one is best for you:

  • as1: FLA published in ActionScript 1.0.
  • as2: FLA published in ActionScript 2.0.
  • as3: FLA published in ActionScript 3.0.
  • mtasc: AS files written in ActionScript 2.0, compiled with MTASC (no FLA).
  • mxmlc: AS files written in ActionScript 3.0, compiled with Flex Builder/mxmlc.
  • flex: AS files written in ActionScript 3.0, compiled with Flex Builder/mxmlc.

Figure c: Copying the MochiAd.as class file.
(Click image to restart animation)

Once you have chosen a folder, open that folder and you will see the MochiAds.as file and an example that demostrates how to use it (fig.b). The only file you will need to copy is the MochiAd.as file. All of the other files are in support of the example.

Simply copy the MochiAd.as file and paste it into the location where you are publishing your game. You do not need to create a special folder for the include (fig.c).

Adding the In-game Code:

The in-game code is a one-line code snippet that you copy from the MochiAds web site. This code is a method call that tells MochiAd.as to launch your ad. You will paste this code into your game in the place where you want the ad to appear. Your code looks something like this:

MochiAd.showPreGameAd({id:"xxxxxxxxxxxxxxxx", res:"360x240"});

There are three types of ads you can place in your game -- a pre-game ad, an inter-level ad and a Click Away ad. Pre-game ads include a preloader bar that grows as your game file is loaded from the web to the player's computer. An inter-level ad is an ad that appears at some point during game-play. The most convenient and unobtrusive time to show ads is usually between game levels, hence the name inter-level ad. Click-away ads are 300x250 ads that can be placed anywhere you specify and will only disappear on a user-initiated action.

You can use the MochiAds web site to customize your code for the particular type of ad and version of ActionScript you need.

ACTIONSCRIPT 3 NOTE: ActionScript 3 developers will also notice that there is an additional parameter named clip which passes a reference to the DisplayObject container for your ad to appear. This is required, and by default this is set to root for pre-game and inter-level ads. See below for more info regarding customizing this parameter.

Pre-game Ad:

Figure d: Pasting the pre-game code into a game FLA.
(Click image to restart animation)

To add a pre-game ad with a preloader to your game, simply get the appropriate in-game code from the MochiAds web site, and paste it into the main timeline of your movie, in the place you've designated for a preloader (fig.d).

If your game is ready, you can test your movie, and you should see the pre-game ad appear as your movie loads. You may test your ads as much as you like while you develop your game. Keep in mind that your ads will not earn money until you complete your game profile which includes a URL to the completed game. You may also upload your SWF file to MochiAds.com for hosting.

Inter-level Ad

Figure e: Pasting the pre-game code into a game FLA.
(Click image to restart animation)

To add an inter-level ad to your game, simply get the appropriate code from the MochiAds web site, and paste it into the main timeline of your movie, in the place you've designated for your inter-level screen (fig.e).

Just like the pre-game ad, you can test your game and see the inter-level ads in action.

Click Away ad

To add a Click Away ad to your game, simply get the appropriate code from the MochiAds web site. Pass in the DisplayObject container / MovieClip which will contain the Click Away ad in the clip parameter. The upper left corner of the 300x250 Click Away ad will be placed at the upper left corner of the DisplayObject container / MovieClip you specify. When you wish to stop displaying the Click Away ad pass your clip to MochiAd.unload().

Flash Player Security Settings:

If you are testing locally outside of the Flash authoring environment and want to be able to see ads, you will need to change the default local playback security settings. In Flash, go to "File -> Publish Settings," then click on the "Flash" tab. At the bottom, under "Local Playback Security", choose "Access network only" and then publish again. Keep in mind that if you are loading any local data that it will no longer be accessible until you change your settings back to "Access local files only." These settings will not affect playback on the web.

Alternatively, you may wish to 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.

You will not need to do this if you are only testing your games in the Flash authoring environment, although you will see Sandbox Violation warnings in the Output panel. Warnings pertaining to MochiAds can be safely ignored.

Alternate In-game Code Placement

Since there are many different ways to architect Flash games, it is very likely that your game development setup is not the same as what you see above. You may have nested MovieClips, or perhaps you are not using the timeline at all. It is possible to place your in-game code in the timeline of a MovieClip as well, and it will execute when the frame where you placed the code is reached.

And You're Done!

That's all that is required to get MochiAds running in your game. When you've completed your game and released it to the world, be sure to complete your profile so that your game can be approved and you can start earning money right away!

1.3 Customizing Your Ad

It is possible to customize many of the visual elements and behaviors of your MochiAds. The MochiAds in-game code has a simple API that allows you to tailor the display to suit your needs. Here's some of the things you can tweak:

  • MovieClip container: You can place your ad into any MovieClip on the stage, or into MovieClips you create with Actionscript.
  • Timing: You can customize fade time of your ads.
  • Colors: Change the colors of the ad preloader bar, background and outline. You can also turn off the solid background.
  • Event Handlers: You can assign custom functions to be called when ads start, load, and end.

The MochiAds API

Your ads can be customized by sending special parameters via your in-game code. Depending on whether you've chosen to display a pre-game or inter-level ad, your options will be slightly different.

The in-game code is passed an object with keys and values to pass to the server. The default code contains two keys -- id, the unique MochiAd identifier, and res, the height x width of your game. These parameters are required.

MochiAd.showPreGameAd({id:"xxxxxxxxxxxxxxxx", res:"360x240"});

You may add more key: value pairs to the object by separating them with commas. You may add the following optional parameters to your object:

  • clip:MovieClip - a MovieClip reference in which to place the ad. Required for click-away ads or if you're using Actionscript 3.0. Otherwise the default is _root. (default: _root)
  • no_bg:Boolean - setting to true allows you to disable the background entirely. (default: false)

The following additional options apply to pre-game ads only:

  • color:Number - the color of the preloader bar as a number. (default: 0xFF8A00)
  • background:Number - the inside color of the preloader bar as a number. (default: 0xFFFFC9)
  • outline:Number - the outline color of the preloader bar as a number. (default: 0xD58B3C)
  • no_progress_bar:Boolean - setting to true allows you to disable the preload progress bar. (default: false)

You can find out the width and height of your ad when it loads. You can use this information to create a custom frame around your ad that matches your game.

  • ad_loaded:Function - ad_loaded is called just before an ad is displayed with the width and height of the ad. (default: function(width:Number, height:Number):Void { }).

You can also find out the progress of the preloader bar. You can use this information to create your own preloader bar when used with the no_progress_bar option.

  • ad_progress:Function - ad_progress is called with the progress of the preloader bar. The progress is a percent (represented from 0 to 100). (default: function(percent:Number):Void { }).

Here is an example of how the code might look if you were to add more options:

MochiAd.showPreGameAd({id:"xxxxxxxxxxxxxxxx", res:"360x240", clip: _root.myClip, no_bg: true, color: 0x006699, outline: 0xFFFFFF});

If you need to add many options, or define functions to handle ad events, you may consider creating an object first, and then referencing that object when you call MochiAds.

var myOptions:Object = {
    id: "xxxxxxxxxxxxxxxx",
    res: "360x240",
    clip: _root.myClip,
    color: 0x006699,
    background: 0x333333,
    outline: 0xFFFFFF,
    ad_loaded: function (width, height) { trace("ad loaded: " + width + "x" + height); }
    ad_progress: function (percent) { trace("preloader percent: " + percent); }
}
MochiAd.showPreGameAd({myOptions});

There is also a tool on the MochiAds web site to customize the appearance of your ad when you set up your in-game code. Often, this is easier than editing the code by hand.

1.4 Changing Ad Behaviors

The MochiAds API described above also allows you to assign your own event handlers to be called by your ad. There are six events:

  • ad_started:Function - a function to call when the ad has started playing. (default: function ():Void { this.clip.stop() })
  • ad_loaded:Function - a function to call just before an ad is displayed with the width and height of the ad. If it is called, it is called after ad_started. (default: function(width:Number, height:Number):Void { }).
  • ad_finished:Function - a function to call when the ad has finished playing. (default: function ():Void { this.clip.play() })
  • ad_failed:Function - a function to call if an ad can not be displayed, this is usually due to the user having ad blocking software installed or issues with retrieving the ad over the network. If it is called, then it is called before ad_finished. (default: function ():Void { })
  • ad_skipped:Function - a function to call if the ad was skipped, this is usually due to frequency capping, or developer initiated domain filtering. If it is called, then it is called before ad_finished. (default: function ():Void { })
  • ad_progress:Function - a function to call when the progress of the preloader bar has changed. The progress is a percent (represented from 0 to 100). (default: function(percent:Number):Void { }).

When you assign custom functions to ad_started and ad_finished in your options object, your ad will no longer stop and play the timeline. Instead, your custom functions will be called.

var myOptions:Object = {
    id: "xxxxxxxxxxxxxxxx",
    res: "360x240",
    clip: _root.myClip,
    ad_started: function ():Void { _global.game.pause(); },
    ad_finished: function ():Void { _global.game.resume(); }
}
MochiAd.showPreGameAd({myOptions});

It is best to explicitly pass a function literal in your options object instead of referencing a function in a separate class. That way, you do not need to worry about losing scope or relying on the Delegate class. If you are using ActionScript 3, though, you can pass a reference to your function without losing scope.

Keep in mind that, if you define custom ad_started or ad_finished event handlers, your timeline will no longer be stopped during the playback of your ad. So, if you still wish to stop your timeline, you will need to be sure your event handler does this.

1.5 MTASC and MXMLC

For those developers who are developing in environments that don't use the Flash IDE, the process for adding MochiAds will be slightly different. In order to get your ads functioning in your game, you will need to:

  1. Make sure that you use MochiAd.as from the corresponding mtasc or mxmlc folder from the MochiAds ZIP package.
  2. Make sure that MochiAd.as is in your root project classpath.
  3. You've added the in-game code in a method that is executed in an instantiated class in your game.

1.6 Adobe Flex

To use MochiAds as an Adobe Flex application's preloader, you will need to:

  1. Make sure that you use MochiAd.as and MochiPreloader.as from the flex folder from the MochiAds ZIP package.
  2. Make sure that MochiAd.as and MochiPreloader.as are in your project classpath.
  3. Tell your MXML application the preloader you want to use:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" preloader="MochiPreloader">
    </mx:Application>
    								 
  4. NOTE: With inter-level ads, MochiAds is unable to tell your game when it has finished via the MovieClip.stop() and MovieClip.start() methods. You must use the ad_started and ad_finished callback methods in your game's options object (described in Section 1.4) to be notified when to start and stop your game.

1.7 ActionScript 3.0 Preloader

The mxmlc folder includes a preloader class (Preloader.as) that provides an example of how to properly compile a preloader into an AS3 SWF compiled with Adobe Flex mxmlc compiler. For the preloader to function correctly, it must load first and execute before your base class and other SWF assets load. In order for this to happen, the Preloader class is included on the first frame of your SWF and all of the other assets are included on the next frame. The Preloader class contains a weak reference to your document class that it uses to instantiate your class after it completely loads your game.

// Change this class name to your main class
public static var MAIN_CLASS:String = "Test";

For the Flex Builder, there is a makefile included in the example which tells the mxmlc compiler to include your Document Class in the second "frame" of your SWF so that the preloader will load first:

mxmlc \
               -default-frame-rate 31 \
               -default-size 550 400 \
               -use-network \
               -optimize=true \
               -output $@ \
               -frame=Test,Test \
               Preloader.as

Notice the compiler option '-frame=Test,Test'.

If you are using FlashDevelop, you need to make sure you're passing "-frame Test, Test" to the mxmlc compiler, which you can set under Compiler Options in Project Properties. Don't forget to change 'Test' to the actual name of your base class.

1.8 More Resources

If you have questions about using MochiAds, you can view our FAQs or visit the support forums for help. Also, if you have suggestions regarding this help document, we encourage your feedback.

2.0 MochiScores API Documentation

This is a simple step-by-step guide to getting MochiScores integrated into your Flash game. Click the links below to skip to any part of this document.

2.1 Prerequisites

First and foremost, make sure that your game is being published for Flash 7 player or greater, and ActionScript 2.0 or 3.0. MochiServices is not compatible with Flash 6 or earlier, nor is it compatible with ActionScript 1.0.

Before you get started, make sure you have done the following:

  1. Sign up for a MochiAds account on www.mochiads.com
  2. Log in and add a new game to your account.
  3. Create a leaderboard for your game.
  4. Download the MochiServices include file ZIP package.
  5. Choose your code options and copy the MochiAds in-game code.

2.2 The MochiScores API

The MochiScores API is a simple, flexible service that allows game developers to create high-score tables for their games. This API currently supports games published to ActionScript 2.0 and Flash Player 7 or later. You will need an internet connection to develop and test MochiServices with your game.

2.3 The MochiServices ZIP Package

When you download and extract the contents of the MochiServices ZIP package, you will notice a series of folders. The first set of folders contains the proper files for the particular version of ActionScript you will be using. Open the folder that corresponds to the version of ActionScript in which your game is written.

In this folder you will see a single folder, named “mochi,” and a series of files. The “mochi” folder contains the MochiServices API classes you will use in your game, and the other files are merely there to demonstrate the usage of the API.

If you want to get started right away, all you need to do is copy the “mochi” folder and paste it into the root classpath of your game. Most often this is the same as the location of your game’s FLA file.

2.4 Connecting to MochiServices

Once you’ve pasted “mochi” folder, it’s time to make sure things work. Open your game FLA and enter the following line of code into on of the first frames of your timeline:

AS2

mochi.MochiServices.connect(”xxx”);

AS3

mochi.MochiServices.connect(”xxx”, root);

… where ‘xxx’ is your MochiAd ID, in quotes. Test your movie, and you should see the following text in your output panel:

MochiServices Connecting…
Waiting for MochiAds services to connect…
connected!

If you see the text above, then that means you have the “mochi” folder in the correct location, and have supplied MochiServices the correct MochiAd ID. Keep in mind that you want to connect to MochiServices as early as possible in your game, and before you make any other API calls. You only need to make this call once in the beginning of your game.

AS3 Requirement - The clip parameter

In ActionScript 3, the root of the Stage cannot be accessed globally. If a Sprite or MovieClip does not have access to the root or to another Display Container that has been added to the display list, then it can not be shown visually on the screen. For this reason, you must supply either the root of your stage or a reference to a Sprite or MovieClip that is a child of the stage to the clip parameter when you call mochi.MochiServices.connect.

2.5 MochiScores Leaderboards

A Leaderboard is a top scores chart to which players can submit their scores. Scores are ranked and tracked in daily, weekly and monthly intervals. Each game that you add to MochiAds can have many Leaderboards, but you must have at least one in order to use the MochiScores API.

After you’ve added your game on the MochiAds web site, you can create a new Leaderboard for it within the dashboard. Each leaderboard will have its own unique board ID. You’ll need that ID in order to make API calls to that leaderboard.

2.6 Displaying the Leaderboard Widget

If you merely want to display the top scores for your game, then simply add the following script to your game:

// stop the main timeline and display the leaderboard
mochi.MochiScores.showLeaderboard({boardID: ”xxx”});

… where ‘xxx’ is your board ID, in quotes. If you’ve already connected to MochiServices and set your board ID, then the leaderboard widget will call stop(); to stop the timeline and then display itself. Players cannot submit a high score this way — they can only see the scores. This is handy if you want to allow players to see the high scores before they play the game.

By default, the showLeaderboard method will call stop(); on the main timeline of your game, and then play(); on the timeline once the leaderboard has been closed by the user. This only occurs if you do not provide a container MovieClip for the leaderboard or your clip is the root of your movie. If you wish to override this behavior, read about providing your own custom onDisplay and onClose handlers Section 2.8: Other Leaderboard Options.

You will also notice that there is a preloader graphic that appears before the leaderboard displays. This graphic will appear in the top left-hand corner of your game unless you provide a resolution in the leaderboard options. If you provide a resolution, then the preloader graphic will appear centered in the area where the leaderboard will display. You can also turn off the preloader graphic entirely by setting a variable in the leaderboard options. Further information on options is detailed below.

In order to allow a player to submit a score after they’ve played your game, then you would call the same method, but also supply an object containing their score, like so:

// stop the main timeline and submit a score to the leaderboard
mochi.MochiScores.showLeaderboard({boardID: ”xxx”, score: 128472});

… where 128472 is the player’s actual score. If you are tracking scores as times, like in a racing game, send the player score in milliseconds. For instance, if the player completed the game in 12.5 seconds, send the integer 12500.

When the leaderboard widget appears, there will be an input box where they can type in their username. After they enter their name, they can then submit their score.

If you have your own registration system within your game, or wish to prevent the player from entering any name they wish, you can supply the username in code, like so:

// stop the main timeline and submit a score and username to the leaderboard
mochi.MochiScores.showLeaderboard({boardID: ”xxx”, score: 128472, name: “janedoe”});

… where ‘janedoe’ is the username, in quotes. This will show the leaderboard widget with the player name already entered, and not editable.

That’s all you need to know to get started! If you’d like to do more advanced customization, read on.

2.7 Saving Your Board ID

If you do not wish to pass the board ID to the showLeaderboard call every time, you can save your board ID by adding the following code to your game:

// set the board ID for all subsequent leaderboard calls
mochi.MochiScores.setBoardID(”xxx”);

… where ‘xxx’ is your board ID, in quotes. This API method sets the board ID for future API calls, so you no longer need to pass the boardID parameter in your API calls. You can always change this by calling this method with a different board ID.

2.8 Other Leaderboard Options

The {} in the showLeaderboard API call is an ActionScript object that is referred to as the options object. These options change the way the leaderboard widget behaves. You can enter as many supported optional parameters into this object as you wish. Below is a list of all possible options.

Basic Options:

score — the player's score to submit (integer, or time in milliseconds)
name — the player's name
boardID — board ID (overrides setBoardID)

Display Options:

clip — MovieClip in which to place the widget. The default is _root
res — the dimensions of your widget, (i.e. "500x400")
width — optional width for the leaderboard within the widget.
preloaderDisplay — show a preloader graphic while the leaderboard loads. The default is true.
numScores — maximum number of scores to display. You can specify any number from 1 to 25, and the default is 10. Changing this alters the height of the leaderboard.
hideDoneButton — set to true if you wish to hide the 'done' button and instead close the leaderboard in code by calling closeLeaderboard.
showTableRank — set to true if you wish to show the player's rank at the bottom of the table.
previewScores — set to true if you wish to display the top scores before the user submits their name and score.

Callback Options:

onDisplay - the function to call when the GUI has displayed. default: function () { clip.stop(); }
onClose - the function to call when the GUI is finished or could not load. default: function () { clip.play(); }
onError - the function to call if the leaderboard cannot load. default: onClose();

2.9 The MochiScores API

This is the complete list of MochiScores API calls. Most developers will only need to use connect, setBoardID, and showLeaderboard. The other calls offer additional functionality to allow advanced developers to create their own custom leaderboards using the MochiServices back-end.

mochi.MochiServices.connect(id:String, clip:Object, onError:Object):Void
Connects and initializes the API.
@param id — MochiAds id of the game
@param clip — the MovieClip or Sprite in which to load the API (optional for all but AS3, defaults to _root) in AS3 clip must be dynamic
@param onError — a function to call upon connection or IO error
mochi.MochiScores.setBoardID(boardID:String):Void
Sets the name of the mode to use for categorizing submitted and displayed scores.
@param boardID — The unique string name of the mode
mochi.MochiScores.showLeaderboard(options:Object):Void
Displays the leaderboard GUI showing the current top scores.
@param options — optional parameters <see: Leaderboard Options>
mochi.MochiScores.closeLeaderboard():Void
Closes the leaderboard GUI (Same as if the player clicked 'Done' on the leaderboard)
mochi.MochiScores.submit (score:Number, username:String, callbackObj:Object, callbackMethod:Object):Void
Submits a score to the server. Will send a scores object to the callback <see: Scores data format>
@param name — the string name of the user.
@param score — the number representing a score. If the score is time, send it in milliseconds.
@param callbackObj — the object or class instance containing the callback method
@param callbackMethod — the string name of the method to call when the score has been sent
mochi.MochiScores.requestList (callbackObj:Object, callbackMethod:Object):Void
Returns an array of at most 50 score objects. Will send a scores object to the callback <see: Scores data format>
@param callbackObj — the object or class instance containing the callback method
@param callbackMethod — the string name of the method to call when the score has been sent. default: "onLoad"
mochi.MochiScores.scoresArrayToObjects (scores:Object):Void
Converts the array of arrays returned by requestList into an array of objects whose keys are derived from cols.
@param scores — the scores object returned to the requestList callback method
mochi.MochiScores.getPlayerInfo (callbackObj:Object, callbackMethod:Object):Void
Retrieves all persistent player data that has been saved in a SharedObject.

2.10 Error Handling

All web services such as this require an internet connection in order to function properly. Since it is possible that a player's internet connection becomes unavailable during gameplay, it's possible that these services may not become available. In order to handle this possibility, there are additional error handlers you can pass to the services.

The MochiServices.connect method also includes the ability to pass an onError method. This method will be invoked if MochiServices cannot connect to the server or any IO errors occur in the future. You can also pass an optional onError handler showLeaderboard in the options object. This will be invoked if the leaderboard cannot load for some reason. By default, the onClose method is called if an error occurs.

All onError handlers will receive status codes that describe the error. The possible errors are:

  • NotConnected — Services were unable to connect or attach to a clip in the current movie.
  • IOError — Services has connected but cannot transfer data to and from the server.

Other methods, such as requestList and submit, do not have onError handlers. However, you can check the results that are returned to see if an error occurred. Upon error, the result object will return a variable named 'error' whose value will be true. Also, a variable named 'errorCode' will return one of the above status codes.

2.11 Custom Leaderboards and Scores Data

If you would like to create your own custom Leaderboard, you can use the MochiScores API to submit scores and retrieve up to 50 scores from your leaderboard. To retrieve scores data, you must first set your board ID using the setBoardID method, and then call requestList, providing a callback method to receive the scores data object.

mochi.MochiScores.setBoardID("xxxxxxxxxxxxxxxx"); // set the board ID to the leaderboard you wish to work with
mochi.MochiScores.requestList(this, "onScoresReceived"); // request the scores and send them to the onScoresReceived method in this object or class

Your callback method should accept a single parameter of type Object. This object will contain the scores object. If there is an error, the object will contain a variable named error whose value is true, as well as a variable named errorCode which explains the error.

//
//
public function onScoresReceived (args:Object):Void {

    if (args.scores != null) {
        
        trace("Scores received!");
        
        var newScores:Object = MochiScores.scoresArrayToObjects(args.scores);
        
    } else {
        
        if (args.error) {
            trace("Error: " + args.errorCode);
        }
        
    }
    
}

If you are using the submit and requestList API calls to create your own custom Leaderboard, you will receive your scores data in the following format:

{
now: 1197420828414.14,
places: { daily: 1, weekly: 2, monthly: 3 }, counts: { daily: 2, weekly": 4, monthly: 8 }, daily: { cols: ["name", "geo", "score", "timestamp"], rows: [["george", "us", 3333, 1197420828414.14], …]},
weekly: { cols: ["name", "geo", "score", "timestamp"], rows: [["george", "us", 3333, 1197420828414.14], …]},
monthly: { cols: ["name", "geo", "score", "timestamp"], rows: [["george", "us", 3333, 1197420828414.14], …]}
}

This is an ActionScript object that contains four variables:

now — the current server timestamp in milliseconds since the epoch
places — the rank that the player's score achieved in each table
counts — the number of scores in each table
daily — scores for the daily table
weekly — scores for the weekly table
monthly — scores for the monthly table

The daily, weekly and monthly variables are objects that contain the following variables:

cols — an array containing the column keys
rows — an array of row arrays. each row array contains the values that correspond to each column key

You may also convert your scores from rows and columns to a list of objects by sending the scores data to MochiScores.scoresArrayToObjects. This will return a new object where each row is an object with key-value pairs. Shown below is an example of how the daily scores would be converted:

daily { [{name: "george", geo: "us", score: 3333, timestamp, 11974208328414.14}, {name: "george", geo: "us", score: 3333, timestamp, 11974208328414.14}, …] }

3.0 MochiAds Version Control and Encryption

3.1 Overview

Our version control and encryption technology enables you to create a special version of your SWF which can be distributed across the Internet as a stand-alone game file. Unlike many other services out today, this is not dependent on our servers or our uptime. In a nutshell, it’s just like any other game only it routinely checks in and will self-update if there is a new version available no matter where it’s played online. If there’s a newer version online, the game will be patched while the game is loading (it only sends minimum differences, so it doesn’t have to download the whole game over again).

As an added bonus, the special version of your SWF also offers an extra layer of encryption sauce to keep hackers and decompilers away.

3.2 Test Your Game For Compatibility

The encryption and version control tool embeds games into an AS3 loader SWF. The Flash Player treats games differently when loaded this way than when loaded by either through an HTML page or directly into a browser.

To test for compatibility, loading your game using the LoaderTest utility to see if you can reproduce the problem. LoaderTest uses the same underlying Flash features that the encryption and version control tool's loader SWF uses. If the problems are still present when using LoaderTest, then you will need to make changes to your game. If the problems are not present, then notify us, and we will investigate the problem.

3.3 Preparing AS3 games

AS3 display list membership

Adobe’s Flash Player treats AS3 SWFs loaded into another AS3 SWF differently than when it’s loaded directly by the browser. In particular, the main object is not added to the display list until after the constructor is called whereas when loaded directly the main object is already attached to the display list. This results in the stage and parent properties being set to ‘null’ (and likely resulting in null object references).

This can usually be worked around by moving any code that needs to interact with the stage being moved to an event listener. Event.ENTER_FRAME, Event.INIT, or Event.ADDED_TO_STAGE events are good candidates for this.

3.4 Preparing AS2 games

AS2 Sound

Some sounds may not play properly in AS2 games within an AS3 loader when the sound is not attached to a movieclip. To get around this, you should ensure your sounds are always attached to a movieclip:

var s = new Sound(mc);

The following is an example of how you can handle sounds in your AS2 games so they are always compatible with AS3 loaders. At the top level of the .as files, the following code initially creates all of the different Sound objects on their own MovieClip:

var core = this;
var make_sound = function (mc_name, depth, volume, name) {
    var mc = core.createEmptyMovieClip(mc_name, depth);
    var snd = new Sound(mc);
    snd.setVolume(volume);
    snd.attachSound(name);
    return snd;
};
var s_newline = make_sound('so_newline', 200, 30, 'newlineMP3');
var s_skull = make_sound('so_skull', 201, 100, 'skullMP3');
var s_doubleskull = make_sound('so_doubleskull', 202, 100, 'doubleskullMP3');
var s_success = make_sound('so_success', 203, 30, 'successMP3');
var s_timer = make_sound('so_timer', 204, 100, 'timerMP3');

Later, when a sound should be played, there's a line like:

core.s_skull.start(0, 1);

Using _root and _level0

It is not recommended to use _root or _leveln as references in your game. If you are experiencing problems when testing your game for compatibility, replace these references and test again.

AS2 games encrypted with SWF Protect

Using SWF Protect mangles the AS2 byte code, making it impossible to find the verification token. A workaround is to instead place the verification token as an export identifier. Here are instructions on how to do this:

  1. Open the Library window in Flash.
  2. Right click on any asset that is not already exported (but preferably one that is used anyways).
  3. Select “Linkage…”
  4. Check “Export for ActionScript"
  5. In text box labeled “Identifier”, enter “XXXXXXXX”
  6. Click “OK”.

NOTE: Where 'XXXXXXXX' should be replaced with your game's actual ID

3.5 Preparing AS1 games

Case-sensitivity: Users have reported that AS1 games loaded into AVM1Movie are suddenly case sensitive, whereas normally they are case-insensitive.

3.6 Third Party APIs written in AS2

Usually these APIs work by cross-scripting a SWF to inject new code into AS2 games. However, Flash does not support cross-scripting between AS2 and AS3, and the version control and encryption loader SWF uses AS3, preventing the API from being injected correctly.

NOTE: LocalConnection APIs will still work, but sites may not provide these for AS2.