Packagecom.myflashlab.air.extensions.gameCenter
Classpublic class Leaderboard
InheritanceLeaderboard Inheritance flash.events.EventDispatcher

An object used to read data from a leaderboard stored on Game Center. Your game uses GKLeaderboard objects when it wants to retrieve localized information about a specific leaderboard or to retrieve scores from a leaderboard. Typically, you do this when you want the data needed to implement your own custom leaderboard user interface.

During the development process, you create the leaderboards for your game on App Store Connect.

To retrieve information about the available leaderboards, use the Leaderboard.load() static method.

To request score data from Game Center, your game allocates and initializes a Leaderboard object, configures its search properties, and then calls the object’s loadScores method. GameKit retrieves the score data from Game Center and calls your completion handler.

The search properties are used to filter the score data returned to your game:

The algorithm used by the GKLeaderboard object is as follows:



Public Properties
 PropertyDefined By
  groupIdentifier : String
[read-only] The identifier for the group the leaderboard is part of.
Leaderboard
  identifier : String
The named leaderboard to retrieve information from.
Leaderboard
  isLoading : Boolean
[read-only] A Boolean value that indicates whether the leaderboard object is retrieving scores.
Leaderboard
  localPlayerScore : Score
[read-only] The score earned by the local player.
Leaderboard
  maxRange : int
[read-only] The size of the leaderboard.
Leaderboard
  playerScope : int
A filter used to restrict the search to a subset of the players on Game Center.
Leaderboard
  scores : Vector.<Score>
[read-only] An array of Score objects that contains the scores returned by the search.
Leaderboard
  timeScope : int
A filter used to restrict the search to scores that were posted within a specific period of time.
Leaderboard
  title : String
[read-only] The localized title for the leaderboard.
Leaderboard
Public Methods
 MethodDefined By
  
initNew($players:Vector.<Player> = null):Leaderboard
[static] Initializes a default leaderboard request.
Leaderboard
  
load($callback:Function):void
[static] Loads the list of leaderboards from Game Center Below shows what parameters the callback function must have function($leaderboards:Vector.<Leaderboard>, $error:String):void { // $leaderboards: is an array of Leaderboard objects that provides the leaderboards for your game.
Leaderboard
  
loadImage($callback:Function):void
The image associated with the default leaderboard.
Leaderboard
  
loadScores($callback:Function):void
Retrieves a set of scores from Game Center.
Leaderboard
  
setRange($begin:int, $end:int):void
The numerical score rankings to return from the search.
Leaderboard
Property Detail
groupIdentifierproperty
groupIdentifier:String  [read-only]

The identifier for the group the leaderboard is part of. If your game was configured to be part of a group in App Store Connect, this property holds the identifier you assigned to the group.


Implementation
    public function get groupIdentifier():String
identifierproperty 
identifier:String

The named leaderboard to retrieve information from. If non-nil, Game Center only returns scores from the matching leaderboard. If nil, all scores previously reported by the game are searched. Default is nil.


Implementation
    public function get identifier():String
    public function set identifier(value:String):void
isLoadingproperty 
isLoading:Boolean  [read-only]

A Boolean value that indicates whether the leaderboard object is retrieving scores. The value of the loading property is true if the leaderboard object has any pending requests for scores.


Implementation
    public function get isLoading():Boolean
localPlayerScoreproperty 
localPlayerScore:Score  [read-only]

The score earned by the local player. This property is invalid until a call to loadScores() is completed. Afterward, it contains a score object representing the local player’s score on the leaderboard given the filters you applied to the query.


Implementation
    public function get localPlayerScore():Score
maxRangeproperty 
maxRange:int  [read-only]

The size of the leaderboard. Returns -1 if loadScores has not been completed on this leaderboard yet.


Implementation
    public function get maxRange():int
playerScopeproperty 
playerScope:int

A filter used to restrict the search to a subset of the players on Game Center. The playerScope property is ignored if the leaderboard request was initialized using the initNew($players) method. Otherwise, if initNew() is used, the playerScope property determines which players are included in the request for high scores. The default is PlayerScope.GLOBAL.


Implementation
    public function get playerScope():int
    public function set playerScope(value:int):void
scoresproperty 
scores:Vector.<Score>  [read-only]

An array of Score objects that contains the scores returned by the search. This property is invalid until a call to loadScores() is complete. Afterward, it contains the same score objects that were returned to the completion handler.


Implementation
    public function get scores():Vector.<Score>
timeScopeproperty 
timeScope:int

A filter used to restrict the search to scores that were posted within a specific period of time. This property determines how far back in time to look for scores. The default value is TimeScope.ALL_TIME.


Implementation
    public function get timeScope():int
    public function set timeScope(value:int):void
titleproperty 
title:String  [read-only]

The localized title for the leaderboard. If you initialized a new leaderboard object, this property is invalid until a call to loadScores() is complete. Afterward, it contains the localized title for the leaderboard identified by the identifier property.


Implementation
    public function get title():String
Method Detail
initNew()method
public static function initNew($players:Vector.<Player> = null):Leaderboard

Initializes a default leaderboard request. If $players parameter is not null, Initializes a leaderboard request to retrieve the scores of a specific group of players.

A leaderboard object initialized with this method uses the playerScope, timeScope, and range properties to search Game Center for scores. If $players parameter is not null, a leaderboard object initialized with this method ignores the playerScope and range properties. Instead, it retrieves scores for the specific list of players whose Player objects are included in the $players parameter.

Parameters

$players:Vector.<Player> (default = null) — An array of Player objects that holds the player identifiers to be retrieved. can be null.

Returns
Leaderboard — An initialized leaderboard request.
load()method 
public static function load($callback:Function):void

Loads the list of leaderboards from Game Center

Below shows what parameters the callback function must have
     function($leaderboards:Vector.<Leaderboard>, $error:String):void
     {
         // $leaderboards: is an array of Leaderboard objects that provides the leaderboards for your game. If an error occurred, this value may be non-nil. In this case, the array holds whatever data Game Kit was able to download before the error occurred.
         // $error: If an error occurred, this error object describes the error. If the operation completed successfully, the value is nil.
     }
     

Parameters

$callback:Function — is called when the categories have been retrieved from the server.

loadImage()method 
public function loadImage($callback:Function):void

The image associated with the default leaderboard.

Below shows what parameters the callback function must have
     function($leaderboard:Leaderboard, $photo:String, $error:String):void
     {
         // $leaderboard: is a reference to the object which initiated this method.
         // $photo: Contains the image path associated with the leaderboard.
         // $error: If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.
     }
     

Parameters

$callback:Function — to be called after the scores are retrieved from the server.

loadScores()method 
public function loadScores($callback:Function):void

Retrieves a set of scores from Game Center.

Below shows what parameters the callback function must have
     function($leaderboard:Leaderboard, $scores:Vector.<Score>, $error:String):void
     {
         // $leaderboard: is a reference to the object which initiated this method.
         // $scores: is an array of Score objects that holds the requested scores. If an error occurred, this value may be non-nil. In this case, the array holds whatever score data could be retrieved from Game Center before the error occurred.
         // $error: If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.
     }
     

Parameters

$callback:Function — to be called after the scores are retrieved from the server.

setRange()method 
public function setRange($begin:int, $end:int):void

The numerical score rankings to return from the search. The range property is ignored if the leaderboard request was initialized using the initNew($players) method. Otherwise, if initNew() is used, the range property is used to filter which scores are returned to your game. For example, if you specified a range of [1,10], after the search is complete, your game receives the best ten scores. The default range is [1,25].

The minimum index is 1. The maximum length is 100.

Parameters

$begin:int
 
$end:int