Package | com.myflashlab.air.extensions.gameCenter |
Class | public class Score |
Inheritance | Score flash.events.EventDispatcher |
An object containing information for a score that was earned by the player. Your game creates Score objects to post scores to a leaderboard on Game Center. When your game retrieves score information from a leaderboard, those scores are returned as Score objects.
Scores and leaderboards work together to help you create a better game. Whenever a new Score object is created, it is associated with a leaderboard. You must ensure that the score being sent to a leaderboard is compatible with the leaderboard scoring format set in App Store Connect. See Leaderboards and Leaderboard Sets for information on how to create a leaderboard in App Store Connect.
To report a score to Game Center, your game allocates and initializes a new object, sets the value property to the
score the player earned, and then calls the Score.report
method. The mechanism your game uses to
calculate scores is up to you to design; scores are only compared within your game.
Property | Defined By | ||
---|---|---|---|
context : Number
An integer value used by your game. | Score | ||
date : Date [read-only]
The date and time when the score was earned. | Score | ||
formattedValue : String [read-only]
Returns the player's score as a localized string. | Score | ||
leaderboardIdentifier : String
The identifier for the leaderboard. | Score | ||
player : Player [read-only]
the player that earned the score. | Score | ||
rank : int [read-only]
The position of the score in the results of a leaderboard search. | Score | ||
shouldSetDefaultLeaderboard : Boolean
A Boolean value that indicates whether this score should also update the default leaderboard. | Score | ||
value : Number
The score earned by the player. | Score |
Method | Defined By | ||
---|---|---|---|
challengeCompose($msg:String, $players:Vector.<Player>, $callback:Function):void
Provides a challenge compose view controller with pre-selected player identifiers and a preformatted,
player-editable message. | Score | ||
[static]
Returns an initialized score object for the specified leaderboard and player. | Score | ||
[static]
Reports a list of scores to Game Center. | Score |
context | property |
context:Number
An integer value used by your game. The context property is stored and returned to your game, but is otherwise ignored by Game Center. It allows your game to associate an arbitrary value with the score data reported to Game Center. You decide how this value is interpreted by your game. For example, you might use the context property to store flags that provide game-specific details about a player’s score, or you might use the context as a key to other data stored on the device or on your own server. The context is most useful when your game displays a custom leaderboard user interface.
could be NaN in case of an error
public function get context():Number
public function set context(value:Number):void
date | property |
date:Date
[read-only] The date and time when the score was earned. When you initialize the new score object, the date property is automatically set to the current date and time.
public function get date():Date
formattedValue | property |
formattedValue:String
[read-only]
Returns the player's score as a localized string. This property is invalid on a newly initialized score object. On a score returned from GameKit, it contains a formatted string based on the player's score. You determine how a score is formatted when you define the leaderboard in App Store Connect.
Never convert the value property into a string directly; always use this method to receive the formatted string.
public function get formattedValue():String
leaderboardIdentifier | property |
leaderboardIdentifier:String
The identifier for the leaderboard.
public function get leaderboardIdentifier():String
public function set leaderboardIdentifier(value:String):void
player | property |
player:Player
[read-only] the player that earned the score. When you initialize a new score object, the player property is set to the local player. If the score object was returned to your game by loading scores from Game Center, the player property identifies the player who recorded that score.
public function get player():Player
rank | property |
rank:int
[read-only] The position of the score in the results of a leaderboard search. Returns -1 if any problem. The value of this property is only valid on score objects returned from Game Center. The rank property represents the position of the score in the returned results, with 1 being the best score, 2 being the second best, and so on.
public function get rank():int
shouldSetDefaultLeaderboard | property |
shouldSetDefaultLeaderboard:Boolean
A Boolean value that indicates whether this score should also update the default leaderboard. If the value of
this property is true, when the score is reported to Game Center, Game Center also updates the local player's
default leaderboard to match the value stored in the leaderboardIdentifier property of the score object. This
matches the behavior of the LocalPlayer class's setDefaultLeaderboardId
class method. If the value
of this property is false, the default leaderboard is not changed by reporting the score. The default value of
this property is false.
public function get shouldSetDefaultLeaderboard():Boolean
public function set shouldSetDefaultLeaderboard(value:Boolean):void
value | property |
value:Number
The score earned by the player. You can use any algorithm you want to calculate scores in your game. Your game must set the value property before reporting a score, otherwise an error is returned.
The value provided by a score object is interpreted by Game Center only when formatted for display. You determine how your scores are formatted when you define the leaderboard in App Store Connect.
public function get value():Number
public function set value(value:Number):void
challengeCompose | () | method |
public function challengeCompose($msg:String, $players:Vector.<Player>, $callback:Function):void
Provides a challenge compose view controller with pre-selected player identifiers and a preformatted, player-editable message.
Below shows what parameters the callback function must havefunction($score:Score, $didIssueChallenge:Boolean, $sentPlayerIDs:Array(String)):void { // $score: is a reference to the object which initiated this method. // $didIssueChallenge: is a Boolean variable designating if the challenge was sent out. // $sentPlayerIDs: is an array of Player objects containing the player identifiers that the challenge was sent to. }
Parameters
$msg:String — The preformatted, player-editable message that is being sent to other players.
| |
$players:Vector.<Player> — An array of Player objects that contains the player identifiers that the challenge is to be
sent to.
| |
$callback:Function — is called after the view controller has been displayed. Contains the reason the handler was
called and all player identifiers that the challenge was sent to.
|
initNew | () | method |
public static function initNew($leaderboardId:String, $player:Player = null):Score
Returns an initialized score object for the specified leaderboard and player. if the $player
param
is null, local player will be used instead.
Your game explicitly allocates and initializes a score object using the designated player and current date when it needs to report a new score to Game Center.
Parameters
$leaderboardId:String — Identifies the leaderboard that the score is being sent to.
| |
$player:Player (default = null ) — The Player object identifying the player who's score is being initialized.
|
Score — An initialized score object, or nil if an error occurred.
|
report | () | method |
public static function report($scores:Vector.<Score>, $challenges:Vector.<Challenge>, $callback:Function):void
Reports a list of scores to Game Center. if $challenges
param is not null, all eligible challenges
will be submitted too.
Use this class method whenever you need to submit scores to Game Center, whether you are reporting a single score or multiple scores. The method runs through the array of Score objects, submitting scores one at a time.
The Score object is initialized with the leaderboard ID for the leaderboard it reports its score to and then the
value
and context
for the score are assigned. The leaderboard ID must be the identifier
for a leaderboard you configured in App Store Connect. Scores are always reported for the current local player
and never for friends.
function($error:String):void { // $error: If an error occurred, this object describes the error. If the operation completed successfully, this value is nil. }
Parameters
$scores:Vector.<Score> — An array of Score objects that contains all of the scores to be reported.
| |
$challenges:Vector.<Challenge> — (can be null) An array of Challenge objects that represents all challenges associated
with the reported scores.
| |
$callback:Function — is called when the download is completed.
|