Login   |   Sign Up
Developer Home > Score API for AS3

MindJolt Score Submission API for AS3

2008/02/27 - The MindJolt AS3 API is currently in beta release.

As such, we appreciate your understanding as we work through any bugs or issues that may arise. We also welcome any comments or feedback on how we can improve the API functionality, and the ease of installation.

There are four ways you can install the API. We recommend using the MXP component if possible, because it's just so easy to do! For those that can't use components, there is an actionscript snippet to use instead.


Installation by using components (highly recommended)

Pick one of the three choices below to install the MindJolt API using easy, packaged components:

MXP

This is the recommended choice. If you haven't already done so, install the Adobe Extension Manager. Once it is installed, just click on the MXP file, and it'll automatically add the MindJolt API to your components panel, for easy access whenever you want to use it.

(Now all you have to do is open your game, and drag the MindJoltAPI component from the Components panel to the stage of your game, and the API is installed!)

download MXP component

SWC

If you do not want to use the Adobe Extension Manager, you can manually install the MindJolt API into your Components panel by doing the following:

  1. Close Adobe Flash
  2. Save the SWC file into the following folder: (you'll have to create the MindJolt subfolder)
  3.     Windows: C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components\MindJolt
            (substitue "en" for whatever your language code is)
        Macintosh: Macintosh HD:Applications:Adobe Flash CS3:Configuration:Component:MindJolt
  4. Startup Adobe Flash

(Now all you have to do is open your game, and drag the MindJoltAPI component from the Components panel to the stage of your game, and the API is installed!)

download SWC component

FLA

If you do not want to add the MindJolt API into your Components panel (which you should do, so you only have to deal with this once!!!), then you can open our sample .fla file, copy the MindJoltAPI component from its library, and paste it onto the stage of your game.

download FLA sample with included component

Manual installation by using actionscript code snippet

Ok, so you can't (or don't want to) use components. That's ok, you can still use the API by inserting this snippet of actionscript instead.

Below is a code snippet that will load the API manually.

This code snippet needs to happen as EARLY as possible when your game starts.

You will need access to "root" to be able to get the path to the API that we'll pass in via FlashVars. After you lead the API from that path, you need to keep track of the API instance yourself, so you have it when you want to submit the score.


import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;

// You'll use this variable to access the API
//   (make sure you can access it from wherever you will later call submitScore)
var MindJoltAPI:Object;



//////
// All of this code should be executed at the very beginning of the game
//

// get the parameters passed into the game
var gameParams:Object = LoaderInfo(root.loaderInfo).parameters;

// manually load the API
var urlLoader:Loader = new Loader();
urlLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadFinished);
urlLoader.load(new URLRequest(gameParams.mjPath || "http://static.mindjolt.com/api/as3/scoreapi_as3_local.swf"));
this.addChild(urlLoader);
function loadFinished (e:Event):void {
    MindJoltAPI=e.currentTarget.content;
    MindJoltAPI.service.connect();
    trace ("[MindJoltAPI] service manually loaded");
}


How to use it!!!

Now that you have the API installed through one of the above methods, you need to get access to it in the code to submit the score.

If you are using one of the components, you can get access just by using the import statement below. But, if you were using the manual code snippet, then you'll have to get access to the MindJoltAPI variable you declared in the script instead.

    import com.mindjolt.api.as3.MindJoltAPI;

Then add the line of code that will submit the score.

You simply need to provide the score. And, if you use game modes, you should provide the current mode the player is playing in. (Example game modes: "easy", "normal", "hard", etc.)

The submitScore call should be placed wherever you compute the final score for the game.

For example, suppose you store the score in a variable called "currentScore".

  1. Submitting a score without a game mode
  2.     MindJoltAPI.service.submitScore(currentScore);

  3. Submitting a score with a game mode
  4.     MindJoltAPI.service.submitScore(currentScore, "easy");

Only put in a game mode if you have more than one mode in your game. This allows us to track the high scores for each game mode separately.