Thursday, January 15, 2009

MindJolt API








MindJolt says there are 4 ways to install the API, 3 of them using components and the last one is manually done using action script, lets take a look at them.

Note: If you dont want to deal with adobe extensions jump to step 3.

Installation using components (highly recommended):

1-MXP

-Install Adobe Extension Manager .
-download the MXP component.
-After installing the extention, run it and goto file>Install Extension and choose the MindJoltAPI component.
-Now go to your flash file and go to Window>Components and you will find the component under the name MindJoltAPI drag it and drop it on te stage.

2-SWC

If you dont want to download the extension manager do the following:

-Close adobe flash
-Download the SWC File.
-Follow this path C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components\ in Components create a new folder and name it MindJolt and paste the SWC file inside it.
-Now open flash and go to Window>Components and you will find the component under the name MindJoltAPI drag it and drop it on te stage.

3-FLA

If you dont want to deal with adobe extensions, then do the following:

-Download the Sample FLA File .
-Open it and copy the MindJoltAPI component from the library and paste it in your flash file.


Manual installation by using actionscript code snippet:

4-Action Script

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.

__________________code start____________________

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");
}
__________________code end____________________


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

MindJoltAPI.service.submitScore(currentScore);

2-Submitting a score with a game mode

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.


for more info visit MindJolt API

No comments:

Post a Comment