Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Using the GameCenter Adobe AIR native extension for iOS

by Alex Liebert

Alex Liebert
  • Milkman Games

Content

  • Setting up your game in iTunes Connect
  • Including the GameCenterAPI library
  • Getting started with the API
  • Updating your application descriptor
  • Building the application
  • Understanding the iOS Sandbox
  • Troubleshooting
  • Where to go from here

Created

15 May 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR Flash Builder Flash Professional gaming iOS mobile Native extensions sandbox

Requirements

Prerequisite knowledge

Experience building games for iOS with Flash Builder and Adobe AIR will help you make the most of this article.

 

Additional required other products

  • Milkman Games GameCenter iOS Extension

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flash Professional (Download trial)
  • Adobe AIR SDK

With the GameCenter iOS AIR native extension from Milkman Games, you can rapidly add support for great social gaming features via Game Center on iOS devices. The GameCenter iOS extension API makes it easy to integrate leaderboards, achievements, and user authentication into your Adobe AIR app via a simple and familiar ActionScript 3 interface.

With the GameCenter iOS extension, you can:

  • Submit scores and achievements to Game Center via ActionScript 3
  • Show the native iOS Leaderboards and Achievements panels in your game
  • Log users into Game Center and retrieve their name, ID, and other details
  • Jumpstart development by exploring a complete sample application, ActionScript 3 documentation, and a getting started guide
  • Use the iOS Game Center sandbox system for testing
  • Deploy to all iPad, iPhone, and iPod Touch devices running iOS 4.1 or greater—and check if the device supports Game Center with one function call
  • This tutorial provides details on getting started with the GameCenter extension. If you want to follow all the steps below, you'll need to purchase and download the GameCenter extension.

Setting up your game in iTunes Connect

Before you can use Game Center in your game, you'll need to register the game in iTunes Connect. Follow these steps:

  1. Log into the Apple Developer center at http://developer.apple.com and go to the iOS Developer area.
  2. Click iTunes Connect on the right.
  3. Click Manage Your Applications, and then click Add New App.
Figure 1. Entering information about the app.
Figure 1. Entering information about the app.
  1. Select a default language and then type a Name and SKU Number for your application (see Figure 1). Under Bundle ID, click You Can Register A New Bundle ID Here, which will bring you to the Provisioning Portal.
  2. In the Provisioning Portal, click New App ID (see Figure 2).
Figure 2. Adding a new App ID.
Figure 2. Adding a new App ID.
  1. Type a description for your new app. For Bundle Identifier, type a unique name in the recommended scheme (like com.yourcompany.YourGameName).

Note: Take note of what you choose here, as you'll need to match it exactly later for Game Center to work.

  1. Click Submit and close the Provisioning Portal. Back on the App Information page, select the Bundle ID you just created. If you don't see your new Bundle ID listed, refresh the page or cancel the operation and click New App again.
  2. Click Continue.
  3. Continue through the next couple of steps, entering the release date, pricing tier, version information, rating information, metadata, icons, screenshots, and other required data for your application. If you're just creating a test app, you can set the release date far in the future. At least one screenshot and icon are required to register an application. If you need some dummy images to test with, you can find them in the /tutorialimages folder included with the GameCenter extension package.
  4. Click Save.
  5. Click Manage Game Center (see Figure 3).
Figure 3. Clicking Manage Game Center.
Figure 3. Clicking Manage Game Center.
  1. On the next screen, click Enable.
  2. Under Leaderboard, click Set Up, and then click Add Leaderboard.
  3. On the Add Leaderboard screen, select Choose under Single Leaderboard (see Figure 4).
Figure 4. Choosing the leaderboard type.
Figure 4. Choosing the leaderboard type.
  1. Type a reference name for your leaderboard and a Leaderboard ID. The Leaderboard ID is the internal name for accessing the leaderboard from code. I typed airleaderboard for my ID, and it's what I'll use in this example. Whatever ID you choose, take note of it because you'll need it later to access Game Center from your app. Choose a score format and sort order that makes sense for your scoring system.
Figure 5. Adding the leaderboard language.
Figure 5. Adding the leaderboard language.
  1. Under Leaderboard Localization, click Add Language (see Figure 5).

You can add as many localized languages as you'd like, but you only need one to start.

  1. Type a Name for your leaderboard and select Integer for the score format (simple whole numbers.) The suffix singular is the descriptive term that follows a single value, and the suffix plural is for more than one (for example, I typed point and points respectively).
  2. Click Save.
Figure 6. Adding an achievement language.
Figure 6. Adding an achievement language.
  1. Click Save again, and then click Go Back to return to the management screen.
  2. Under Achievements click Set Up.
  3. Click Add New Achievement.
  4. Enter a reference name, achievement ID, and point value for your achievement. Take note of the achievement ID, as you'll need it later to submit the achievement from ActionScript. I typed airachievement01, which I will use in the rest of this tutorial.
  5. Click No next to Hidden to indicate that this is not a hidden achievement.
  6. Click Add Language (see Figure 6).
  7. Select a language and type a title, pre-earned description, and earned description for your achievement. For details on what these descriptions are for, click the question mark next to each field. You'll need to upload a 512 x 512 icon as well; if you need a test icon, you can reuse the one in the /tutorialimages folder.
  8. Click Save to add the language.
  9. Click Save again to add the achievement.
  10. Click Go Back and then click Done.
  11. Click View Details under Versions. Scroll down to the Game Center area, and click Enable For This Version (see Figure 7).
Figure 7. Enabling Game Center for the application.
Figure 7. Enabling Game Center for the application.

You're now all set up in iTunes Connect!

Including the GameCenterAPI library

The next step is to add the com.milkmangames.nativeexetnsions.GameCenter.ane library to your project. (If you're not using Flash Builder 4.6 and later or Flash Professional CS6 and later, you'll need to add the GameCenterAPI.swc library instead.)

In Flash Professional CS6:

  1. Create a new project of the type AIR for iOS.
  2. Choose File > Publish Settings.
  3. Click the wrench icon next to Script for ActionScript Settings.
  4. Select the Library Path tab
  5. Click Browse For Native Extension (ANE) File and select the com.milkmangames.nativeextensions.GameCenter.ane file

In Flash Builder 4.6:

  1. Go to Project Properties (right-click your project in Package Explorer and select Properties).
  2. Select ActionScript Build Path and click the Native Extensions tab.
  3. Click Add ANE and navigate to the com.milkmangames.nativeextensions.GameCenter.ane file.

In FlashDevelop:

  1. Copy the GameCenterAPI.swc file to your project folder.
  2. In the explorer panel, right-click the SWC and select Add To Library.
  3. Right-click the SWC file in the explorer panel again, select Options, and then select External Library.

Getting started with the API

You can start using the GameCenter extension with a few simple calls. See example/GameCenterExample.as for a full example that shows how to log in, check authentication, show leaderboards, submit scores and achievements, capture errors, and more.

Follow these steps to get started:

  1. Import the API Classes:
com.milkmangames.nativeextensions.ios.*; com.milkmangames.nativeextensions.ios.events.*;
  1. Next, initialize the API and create an instance of the GameCenter object, with your stage:
var gameCenter:GameCenter=GameCenter.create(this.stage);
  1. Check if the device supports Game Center. Although AIR apps will run on iOS 4.0 and higher, Game Center is only available in iOS 4.1 and higher.
if(!GameCenter.gameCenter.isGameCenterAvailable()) { trace(“this device doesn't have gamecenter.”); return; }
  1. Log in to Game Center, and listen for the events that will tell you if the authentication was successful or not. Be sure to listen for the AUTH_FAILED event to avoid an uncaught error:
GameCenter.gameCenter.addEventListener(GameCenterEvent.AUTH_SUCCEEDED,onAuthSucceeded); GameCenter.gameCenter.addEventListener(GameCenterErrorEvent.AUTH_FAILED,onAuthFailed); GameCenter.gameCenter.authenticateLocalUser();
  1. Once you're logged in, you can show the leaderboard for your game. Note that the leaderboard ID being passed in (in this case its "airleaderboard" ) must match the ID you created for the leaderboard in iTunes Connect. Also, you can listen for events to tell you when the leaderboard is shown, and when the user has closed the leaderboard window:
GameCenter.gameCenter.addEventListener(GameCenterEvent.LEADERBOARD_VIEW_OPENED,onViewOpened); GameCenter.gameCenter.addEventListener(GameCenterEvent.LEADERBOARD_VIEW_CLOSED,onViewClosed); GameCenter.gameCenter.showLeaderboardForCategory(this.score,"airleaderboard");
  1. You can show the achievements for your game in much the same way:
GameCenter.gameCenter.addEventListener(GameCenterEvent.ACHIEVEMENT_VIEW_OPENED,onViewOpened); GameCenter.gameCenter.addEventListener(GameCenterEvent.ACHIEVEMENT_VIEW_CLOSED,onViewClosed); GameCenter.gameCenter.showAchievements();
  1. When you want to report a new high score, you can use the code below. Be sure to listen for the success and fail events (you will have an uncaught error if you don't handle a failed submission):
GameCenter.gameCenter.addEventListener(GameCenterEvent.SCORE_REPORT_SUCCEEDED,onScoreReported); GameCenter.gameCenter.addEventListener(GameCenterErrorEvent.SCORE_REPORT_FAILED,onScoreFailed); GameCenter.gameCenter.reportScoreForCategory(this.score,”airleaderboard”);
  1. You can submit achievement progress by calling reportAchievement() . Again, listen for the success and fail events. The first parameter is the achievement ID, which must exactly match an achievement you created earlier in iTunes Connect. The second parameter is the percent of the achievement completed—a value from 0.0 to 100.0.
GameCenter.gameCenter.addEventListener(GameCenterEvent.ACHIEVEMENT_REPORT_SUCCEEDED,onAchievement Reported); GameCenter.gameCenter.addEventListener(GameCenterErrorEvent.ACHIEVEMENT_REPORT_FAILED,onAchievementFailed); GameCenter.gameCenter.reportAchievement("airachievement01",100.0);
  1. You can reset the user's achievements like this:
GameCenter.gameCenter.addEventListener(GameCenterEvent.ACHIEVEMENT_RESET_SUCCEEDED,onAchievementReset); GameCenter.gameCenter.addEventListener(GameCenterErrorEvent.ACHIEVEMENT_RESET_FAILED,onAchievementResetFailed); GameCenter.gameCenter.resetAchievements();

For complete examples of all the available methods, see the GameCenterExample.as file in the /example folder.

Updating your application descriptor

In your application descriptor XML file, you need to specify a link to the extension and specify that you are using the AIR 3.1 SDK. For a working example, see example/app.xml.

  1. If it is not already set, make sure your descriptor file references AIR SDK 3.1:
<application xmlns="http://ns.adobe.com/air/application/3.1">
  1. Include a link to the extension in the descriptor:
<extensions> <extensionID>com.milkmangames.extensions.GameCenter</extensionID> </extensions>

Building the application

If you're using Flash Builder 4.6 or later, or Flash Professional CS6 or later, and have added the GameCenter extension library as described above, then you can compile as you usually do directly from your IDE. If not and you are building your app with the extension from the command line, then you'll need to specify the directory containing the com.milkmangames.nativeextensions.GameCenter.ane file.

Here is an example build command line:

[PATH_TO_AIR_SDK]\bin\adt -package -target ipa-test-interpreter -storetype pkcs12 –keystore [YOUR_KEYSTORE_FILE] -storepass [YOUR_PASSWORD] -provisioning-profile [YOUR_MOBILEPROVISION_FILE] gamecenter.ipa app.xml gcexample.swf -extdir [DIRECTORY_CONTAINING_ANE_FILE]

Understanding the iOS Sandbox

Important: Your app will not be able to interact with Game Center before it is available in the App Store unless you are running in Sandbox mode.

To start in Sandbox mode:

  1. Be sure the .mobileprovision file that you used to build your IPA file was the development version of this file. (You can and should use the distribution version of the .mobileprovision file when building your final app to upload to the App Store.)
  2. Log out of Game Center completely before starting your test app for the first time.
  3. Start your app. When prompted to log in to Game Center, select Create New Account. Do not try to login with your real Game Center account.
  4. Enter any information you want for this new account. It will be a test account in the iOS sandbox, so you just need to remember the email address and password (the email address can be made up.)

If you've done it correctly, the Welcome Back window that iOS shows you when you login should say Sandbox on it (see Figure 8).

Figure 8. The Game Center welcome back window displaying in Sandbox mode.
Figure 8. The Game Center welcome back window displaying in Sandbox mode.

Troubleshooting

Use the tips below to troubleshoot any problems you may be having with the GameCenter extension:

  • If you're having trouble authenticating the user, ensure you have followed the instructions above for using Sandbox mode.
  • If iOS says your app is not recognized by Game Center, verify that the bundle id in iTunes Connect exactly matches the application id in your AIR manifest XML file.
  • If achievements are being reported, but you don't see a banner reporting that the achievement was won, you'll need to add one yourself in the GameCenterEvent.ACHIEVEMENT_REPORT_SUCCEEDED handler. iOS 4 does not have a built-in won achievement banner.
  • If you're stuck in Sandbox mode and want to go back to your regular Game Center account, log out of Game Center, close and uninstall your AIR app, force close the Game Center application, restart Game Center, and log in with your actual personal account. When you run your test app (built with the development version of your .mobileprovision file), you will re-enter Sandbox mode.
  • If your app is halting after making a call, run in debug mode to see if there are any errors. Make sure you are capturing all GameCenter extension events for the calls you are making. You can check the GameCenterEvent.message property to see what went wrong.
  • If you're submitting scores successfully, but don't see them in the leaderboard:
    • Make sure the leaderboardID you're using exactly matches the one you typed in iTunes Connect.
    • Switch to the This Week view and then back to All Time.
    • Logout and log back in with a new Game Center sandbox account, and then submit a new score. Occasionally the sandbox fails to show the scores when there is only one user-submitted score. This does not happen in production. If this is the problem, the preceding steps will resolve it.
  • If Game Center stops trying to login after awhile, uninstall your app, log out of Game Center, and force close the Game Center app. iOS only allows you to ask the user to login three times unsuccessfully before it stops asking. The preceding steps reset this behavior.

Where to go from here

Now that you have the GameCenter extension up and running, you may want to explore the ActionScript 3 documentation or check out the other tools from available from Milkman Games.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

More Like This

  • What's new in Adobe AIR 3
  • Installation and deployment options in Adobe AIR 3
  • Developing cross-platform Adobe AIR applications
  • 10 common mistakes when building Adobe AIR applications
  • Tips for building AIR applications that can be easily updated
  • Adobe AIR and the experience brand
  • Uploading images from CameraRoll and CameraUI
  • Getting started with Adobe AIR for Flex and ActionScript 3 developers
  • Ten tips for building better Adobe AIR applications
  • Deploying Adobe AIR applications seamlessly with badge install

Tutorials and samples

Tutorials

  • Using the iOS Simulator to test and debug AIR applications
  • Using the Amazon In-App Purchase Adobe AIR native extension for Android and Kindle Fire
  • Transferring data with AIR native extensions for iOS – Part 3
  • Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C

Samples

  • Licensing Adobe AIR applications on Android
  • Using web fonts with Adobe AIR 2.5
  • Using Badger for Adobe AIR applications

AIR blogs

More
07/09/2012 Protected: Publishing Adobe AIR 3.0 for TV on Reference Devices
07/08/2012 Source Code: Adobe AIR 3.3 Retina Video Application
07/06/2012 Application specific File Storage on Adobe AIR based ios Application
07/04/2012 Recent Work - iPad/Android App: Inside My toyota

AIR Cookbooks

More
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay
01/20/2012 Skinnable Transform Tool
01/18/2012 Recording webcam video & audio in a flv file on local drive
12/12/2011 Date calculations using 'out-of-the-box' functions

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement