In order to have your games allocated badges for the user in the website, you need to have the badge API.
How to apply for the badge API.
You can apply for the badge api in two ways
1. during upload, a check box is available.
2. when the owner of the game plays a game, the option to apply for a badge will appear in the game play page, below the game.
Once applied, the admin has to approve this request. On Approval, an email is sent to the user, in which will be contained the api key for the game.
Back in the website, A link labeled "Badges" will appear next to each uploaded game, in the "Uploaded Games" section in the users profile. Clicking on it will take the user to the badge view page.
The developer can now start uploading badges for this game. A developer can upload a maximum of 20 badges per game, and these too has to be approved by the admin.
When a developer uploads a badge, which is an image, he has to give the following details.
1. Ttitle for the badge
2. Description
3. Points that the user will get when he/she is rewarded this badge from the game.[there is an upper and lower limit to this points.]
An option to submit the badges for approval is given in the badge-view page. user can click on it to submit the badges once thery are uploaded.
Once the admin approves the badges becomes in the active status.
How to Allocate a badge to a user.
A game file can allocate a badge to a user, by posting the API KEY and BADGE ID to portal strikes api handler.
The developer has to edit his game code, and post the badge to the API handler wherever you may find it necessary. make sure the correct badge id, and API key combination is used.
For AS3 developers
package {
//importing the flash libraries
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
//class to send the URL variables to the server.
public class Badge extends Sprite
{
//private attributes.
private var urlRequest:URLRequest;
private var gameUrl:String;
private var api_key:String;
private var badge_id:String;
private var myVariables:URLVariables;
private var urlLoder:URLLoader;
//constructor
public function Badge():void
{
}
//method to send a request to the server.
public function sendVariables(apiKey:String, badgeId:String, __url:String)
{
gameUrl = __url;
urlRequest = new URLRequest(gameUrl);
urlRequest.method = URLRequestMethod.POST;
//creates a URL request with URL variables.
myVariables = new URLVariables();
myVariables.api_key = apiKey;
myVariables.badge_id = badgeId;
urlRequest.data = myVariables;
urlLoder=new URLLoader()
urlLoder.dataFormat=URLLoaderDataFormat.VARIABLES;
urlLoder.addEventListener(Event.COMPLETE,loadDataFromPhp);
//send the request.
urlLoder.load(urlRequest)
}
//to load data
private function loadDataFromPhp(e:Event)
{
trace(unescape(e.target.data));
}
}
}
You can instantiate the class with the following code
var someName:Badge=new Badge;
When you need to allocate a badge to a user, place a call to the function as shown below
someName.sendVariables(API_KEY_HERE, BADGE_ID_HERE, http://portalstrike.com/api/grantBadge)
Replace the API_KEY, BADGE_ID with the corresponding values obtained from portal strike.
For AS2 developers
// Class to send URL Variables to the server.
class Badge
{
// Create load vars object 'send_lv' for data transfer
private var send_lv:LoadVars;
// Constructor
public function Badge()
{
}
// Method for load data.
public function sendVariables(apiKey:String, badgeId:String, __url:String)
{
send_lv = new LoadVars();
// Gets the value of API KEY, Badge Id and URL
send_lv.api_key = apiKey;
send_lv.badge_id = badgeId;
// Sending data to external web application
send_lv.sendAndLoad(__url, send_lv, "POST");
// Calls 'checkLoadedData' method on 'onLoad'
send_lv.onLoad = checkLoadedData;
}
// if data was loaded
private function checkLoadedData (success:Boolean)
{
// Parse the data returned
if(success)
{
trace(unescape(this.toString()));
}
// Display an error
else
{
trace("Error in connection!!");
}
}
}
In the same way You can instantiate the class with the following code
var someName:Badge=new Badge;
When you need to allocate a badge to a user, place a call to the function as shown below
someName.sendVariables(API_KEY_HERE, BADGE_ID_HERE, http://portalstrike.com/api/grantBadge)
Replace the API_KEY, BADGE_ID with the corresponding values obtained from portal strike.
General Note :
The badge id will not be allocated in the following cases
1. If a guest user is playing the game.
2. The badge allocated was blocked by the administrator
3. The badge id or api key is not valid.
4. The badge has already been allocated.
Once allocated, the badge will pop up for the user under the game.

