On default, clicking the close button on the mochi leaderboard calls play(), which can in case of a timeline controlled movie lead to some problems. That’s why I added an argument to the showLeaderboard function. The following class belongs to my highscore screen that is called when the game ends or is ended.
But, code first:
package {
import flash.display.MovieClip;
import mochi.as3.*;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
dynamic public class ScreenHisc extends MovieClip {
public var sumTries:int;
public var clipRef:MovieClip;
public function ScreenHisc (clipRef, endScore) {
this.clipRef = clipRef;
var o:Object = { //building the boardID};
var boardID:String = o.f(0,"");
MochiScores.showLeaderboard({boardID: boardID, score: endScore, onClose: function(){root.screenHisc.addEventListener(MouseEvent.CLICK, clipRef.restartGame, false, 0, true);Mouse.hide();root.cursor.visible = true;}});
}
}
}
Alright, things are:
- boardID:
- your leaderboards ID given by code (nothing to do here, phew!)
- score:
- whatever score you’d like to send to the leaderboard
- onClose:
- overrides the built-in onClose function ‘play()’
Into this function I added an EventListener which let’s the player click away the highscore screen (that itself contains the actual and the highscore from the localObject), the mouse is re-hidden (was activated for the leaderboard) and the custom cursor is set visible.
Questions or remarks me mateys? Yoho!